javascript - How to know add element to an array if checkbox is checked and remove it if unchecked? -
here code on html. find on google can use this.
<input type="checkbox" ng-true-value="addtitle(cpportfolioitem)" ng-false-value="removetitle(cpportfolioitem)">
here angularjs controller.
$scope.addtitle = function(cpportfolioitem){ $scope.selectedtitles.push(cpportfolioitem.id); console.log('$scope.selectedtitles', $scope.selectedtitles); }; $scope.removetitle = function(cpportfolioitem){ $scope.selectedtitles.splice(cpportfolioitem.id,1); console.log('$scope.selectedtitles', $scope.selectedtitles); };
it doesn't work. have logged in console can see neither push or splice array. maybe ng-true-value
not valid directive? can me on this? appreciate it.
base on documentation ng-true-value
, ng-false-value
value not event handlers. these value set model
when input
checked(ng-true-value
) or unchecked(ng-false-value
).
use this instead or use ng-model
, attach $watch
model.
Comments
Post a Comment