1 <!DOCTYPE html> 2 <html ng-app="app"> 3 <head> 4 <meta charset="utf-8"> 5 <title></title> 6 <script src="./angular.min.js"></script> 7 <style> 8 div{ 9 width: 400px; 10 height: 100px; 11 background: #aaf; 12 } 13 </style> 14 </head> 15 <body ng-controller="ctrl"> 16 <h1> 17 {{count}} 18 </h1> 19 <input ng-model="count"/> 20 <div ng-click="click()">点我</div> <!-- 点击事件 --> 21 <script> 22 angular.module('app',[]) /*找到app模块*/ 23 .controller('ctrl',function($scope){ /*找到控制器*/ 24 $scope.count = 0; /*设定初始值为0*/ 25 $scope.click = function(){ 26 $scope.count += 1; /*触发事件对count加1*/ 27 } 28 }) 29 </script> 30 </body> 31 </html>