How do you iterate over an array of objects for ty

2019-05-11 05:58发布

问题:

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.

回答1:

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.