我在我的HTML中有一个选择(moreCourses是我的控制器的名称):
<select class="form-control" ng-options="course.courseId as course.courseName for course in moreCourses.coursesToshow track by course.courseId | filter: {show: true}" ng-model="course.newcourse" data-ng-change="moreCourses.showCourse(course)">
<option style="display:none" value="">Choose a course</option>
</select>
这是包含select:
对象的数组var coursesToshow =
[{
courseName: 'English for Work',
courseId: 'en-efw',
show: true
},
{
courseName: 'Practice Courses',
courseId: 'en-practice',
show: true
},
{
courseName: 'English for Doctors',
courseId: 'en-efd',
show: true
}];
一切正常,但过滤器不起作用,当用户选择一个选项时,属性的值'变为'false',我已经检查过了。
感谢。
答案 0 :(得分:2)
感谢@Numyx,解决方案是select
的订单,在track by
filter
<select class="form-control" ng-options="course.courseId as course.courseName for course in moreCourses.coursesToshow | filter: {show: true} track by course.courseId" ng-model="course.newcourse" data-ng-change="moreCourses.showCourse(course)">
<option style="display:none" value="">Choose a course</option>