如何在angularjs中单击元素时获取警报消息

时间:2015-01-06 05:22:15

标签: jquery angularjs

我是新的angularJs,尝试点击按钮/元素进行一些dom修改。首先,我只是想知道如何通过角度获得以下小提琴链接中的输出。谁能请你帮忙。

http://jsfiddle.net/dpaq52oo/

$("#clickMe").on("click",function()
{
 alert("hi there");     
});

提前致谢。

2 个答案:

答案 0 :(得分:1)

HTML:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myapp">
<div ng-controller="MyController">
    <div ng-click="clickMe()">Click here and see what happens</div>
</div>
</body>

脚本:

angular.module('myapp', [])
  .controller('MyController', function($scope) {
    $scope.clickMe= function(){
         alert("hi there");  
   }
});

答案 1 :(得分:0)

HTML:

<div ng-app="myapp" ng-controller="myctrl">   
<button ng-click="alertme()">click me</button>
</div>

脚本:

var myapp = angular.module('myapp',[])
  .controller('myctrl',function($scope){
     $scope.alertme = function(){
        alert('hi there');
  }
  });