angularjs中ng-change使用方法


ng-change需與ng-model結合使用,官網說明如下:Note, this directive requires ngModel to be present.

<label for="ng-change-example1">example1:</label>
<input type="checkbox" id="ng-change-example1" ng-model="ngChange"/>
<label for="ng-change-example2">example2:</label>
<input type="checkbox" id="ng-change-example2" ng-model="ngChange" ng-change="change()"/><!--ng-change要結合ng-model使用-->
<p>改變次數:{{count}}</p>

change()方法:

  $scope.count = 0;
  $scope.change = function(){
         if($scope.ngChange){
                 alert('被選中');
         }else{
                 alert('未被選中');
         }
         $scope.count++;
  }

當點擊example2時會觸發change()方法,ngChange變量會發生變化,因此example1也會變化。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM