angularjs - angular.js sets model to null when ng-options filtered -


i have course category , course list select inputs. according selected courses, want filter ng-options user won't select same courses twice

  <td>     <select ng-show="course._courseid" class="form-control"              ng-model="course.lookup_course_id"              ng-options="s.id s.name s in subcourses[course._courseid] | filter:notselectedcourse">       <option value="">select course</option>     </select>   </td> 

and i'm using following function filter selected courses

$scope.notselectedcourse = function(scourse) {     if (!$scope.course_list)       return true;      (var d, = 0; < $scope.course_list.length; i++) {       d = $scope.course_list[i];       if (d.lookup_course_id == scourse.id)         return false;     }      return true; }; 

however, angular.js doesn't update second selectbox value , update model.

when disable filter, works fine need add filter user cannot select same course twice.

here demo, try use select input

any appreciated

hope expecting ..... did put same constraint category selection demo http://embed.plnkr.co/tkr4nwedy45egn48aftp/

// filter/predicate invoked when select renders options each item in categories  ... // if course of categerory has been selected // options can displayed. else option can displayed selected .... $scope._filters.selectablecategories = function(selectedcategoryid) {     return function(item) {                  // 1. selected courses :             // 1.1 course id set/ not null... hence ignore courses user has not yet selected course ...             // 1.2 categerory == item             // 1.3 categerory not current select category ... bcos current selected category selectable ...             //2. if above count  not equal course in category, selectable ...         return $scope._courselist             .filter(function(elm) { return elm._courseid && elm._categoryid !== selectedcategoryid && elm._categoryid === item.id;})             .length != $scope._courses[item.id].length;     } }  // filter/predicate invoked when select renders options each item in courses_of_category  ... // if option has not in selected courses  // options can displayed. else option can displayed selected .... $scope._filters.selectablecourses = function(selectedcategoryid, selectedcourseid) {     return function(item) {         // 1. select courses :             // 1.1 category === selected categerory             // 1.2 course not selected course ... again bcos current selected course selectable ...         // 2. array of courseids ...         // 3. if item's id not in array, item selectable ...         return $scope._courselist             .filter(function(elm) {return elm._categoryid == selectedcategoryid && elm._courseid !== selectedcourseid;})             .map(function(elm){ return elm._courseid; })             .indexof(item.id) < 0;     } } 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -