您好,欢迎来到五一七教育网。
搜索
您的当前位置:首页angularjs中ng-change使用方法

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也会变化。

转载于:https://www.cnblogs.com/loveamyforever/p/6042958.html

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 517ttc.cn 版权所有 赣ICP备2024042791号-8

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务