angularJS中ng-change的用法

时间:2022-07-15 06:50:49
<html>
<head>
<meta charset="utf-8">
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body> <div ng-app="myApp" ng-controller="myCtrl"> <input type="checkbox" ng-model="chk" ng-change="chkchange(chk)"/>点我! </div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.chk = false;
$scope.chkchange = function(chk)
{
chk? alert('选中'):alert('未选中');
}
});
</script> </body>
</html>

ng-change主要用在input标签发生变化时。