1:表达式 事件绑定
PS:ng-click 点击事件 。
<div>
<p>按钮点击:{{conters || 0}}</p>
<bottom ng-click = "conters = conters+1">点击</bottom>
</div>
2:事件方法名 绑定
PS:ng-click = "事件方法名( )" 。
PS:$scope.事件方法名 = function( ){ 函数体 };。
PS:$scope.conters = 0; 给conters默认值0 。
<!doctype html>
<html ng-app = "myapp" ng-controller = "TestController">
<head>
<script src="http://code.angularjs.org/angular-1.0.1.min.js"></script>
</head>
<body>
<div>
<p>按钮点击:{{conters}}</p>
<bottom ng-click = "conterClick()">点击</bottom>
</div>
</body>
<script>
var app = angular.module('myapp', []);
app.controller('TestController', function($scope) {
$scope.conters = 0;
$scope.conterClick = function(){
$scope.conters = $scope.conters+1;
};
});
</script>
</html>
网友评论