Strawberry
Strawberry

Reputation: 67868

How do you iterate over an array of objects for typeahead?

http://angular-ui.github.io/bootstrap/

I want to use the bootstrap's typeahead, and search two different key-pairs in an object. How do I iterate over an array objects?

Also could someone explain what for is this? typeahead="state for state in states | filter:$viewValue"

The for clause is throwing me off and it seems really unclear because state for state shares the same name.

Upvotes: 3

Views: 14004

Answers (1)

zs2020
zs2020

Reputation: 54514

state for state in states is the comprehension expression, short for

angular.forEach(states, function (state) {
    return state;
});

You can take a look at the documentation about the comprehension expression introduced at ngOptions of select directive.

Upvotes: 13

Related Questions