1、AngularJS 事件
ng-click ( 适用标签 :所有,触发事件:单击);
ng-dblclick( 适用标签 :所有,触发事件:双击);
ng-blur(适用标签 : a,input,select,textarea,触发事件:失去焦点);
ng-focus(适用标签 : a,input,select,textarea,触发事件:获取焦点);
ng-change(适用标签 : a,input,select,textarea,触发事件:model更新);
ng-keydown(适用标签 : 所有,触发事件:键盘按键按下,要把$event传过去);
ng-keyup(适用标签 :大部分用在input、textarea, 但适用所有标签,触发事件:键盘按键按下并松开,但要把$event 传过去);
ng-keypress(同上);
ng-mousedown(适用标签 : 所有,触发事件:鼠标按下,左右中间都会触发);
ng-mouseup(适用标签 : a,input,select,textarea,触发事件:鼠标按下弹起,左右中间都会触发);
ng-mouseenter(适用标签 :所有,触发事件:鼠标进入);
ng-mouseleave(适用标签 :所有,触发事件:鼠标离开);
ng-mousemove(适用标签 :所有,触发事件:鼠标移动);
ng-mouseover(适用标签 :所有,触发事件:鼠标进入);
2、AngularJS 实例
<!DOCTYPE html>
<html> <head>
<meta charset="utf-8">
<script src="js/angular.min.js"></script>
</head> <body>
<div ng-app="myApp" ng-controller="myCtrl">
<!-- ng-click 指令 -->
<button ng-click="count = count + 1">点我!</button>
<p>{{ count }}</p> <button ng-click="toggle()">{{text}}</button>
<p ng-hide="myVar">
名:
<input type="text" ng-model="firstName">
<br> 姓名:
<input type="text" ng-model="lastName">
<br>
<br> Full Name: {{firstName + " " + lastName}}
</p>
</div>
</body> </html>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function ($scope) {
$scope.firstName = "John";
$scope.lastName = "Doe";
$scope.flag = false;
$scope.myVar = true;
$scope.text = '点击可见';
$scope.toggle = function(){
$scope.myVar = !$scope.myVar;
$scope.flag = !$scope.flag;
$scope.text = $scope.flag ? '点击消失' : '点击可见';
}
});
</script>