菜鸡学AngularJS 05 事件绑定 (表达式、事件方法名)

2016-07-21  本文已影响19人  菜鸡

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>
上一篇下一篇

猜你喜欢

热点阅读