2015/09/30

AngularJS ng-click

ng-click:可以給予元素有點擊的事件,以div為例

<!DOCTYPE html>
<html ng-app="myApp">
 <head>
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>
  <script type="text/javascript">
   var myApp = angular.module('myApp', []);
   myApp.controller('myController', function($scope){
    $scope.divClick = function(){
     alert("點擊的是一個div");
    };
   });
  </script>
  <meta charset="utf8"/>
  <title>Filter</title>
 </head>
 <body ng-controller="myController">
  <div ng-click="divClick()">Hi</div>
 </body>
</html>

執行結果: