Search code examples
angularjsangular-ui-bootstrapangular-ui-typeahead

Using Angular Typeahead on Nested Objects


I'm trying to use Angular Bootstrap Typeahead on an array of nested objects and I cannot figure out how to write out the typeahead.

My objects in my array are like so:

{
  "category": "Locations",
  "regions": [
    {
      "name": "Northeast",
      "category": "region",
      "states": [
        {
          "name": "New York",
          "category": "state"
          "cities": [
            {
              "name": "Syracuse",
              "category": "city"
            }
          ]
        }
      ]
    } 

I only want to return the name values. So how would I go about writing this out? I currently am writing <input ... typeahead=" filter.name for filter in filters| filter:$viewValue | limitTo:5">


Solution

  • Rather than using "in filters" just do something like "in transformFilters()"

      $scope.transformFilters = function () {
          // Loop over filters and create an array of
              {name: name, category:cat}
    
         return my new array
    
      }