function MyCtrl($scope) {$scope.results = {年份:2013,科目:[{title:'English',grade:'A'},{title:'Maths',grade:'A'},{title:'Science',grade:'B'},{title:'地理',等级:'C'}]};}
If I have an array of objects, and I want to bind the Angular model to a property of one of the elements based on a filter, how do I do that? I can explain better with a concrete example:
I want to filter the second input to the subject with a grade 'C', but I don't want to bind the model to the grade; I want to bind it to the title of the subject that has grade 'C'.
Is this possible, and if so, how is it done?
解决方案
<div ng-repeat="subject in results.subjects | filter:{grade:'C'}">
<input ng-model="subject.title" />
</div>