[英]How Catch Angular JS ng-click event
<button ng-click="btn_save">Save</button>
<button ng-click="btn_update">update</button>
I want to cach and display alert for ng-click event of btn-save only anjular js .give me some best practice for done this job. 我想cach并显示btn的 ng-click事件的警报 -只保存 anjular js。给我一些完成这项工作的最佳实践。
First you need to add an app and a controller where you will implement your logic. 首先,您需要添加一个应用程序和一个控制器,您将在其中实现您的逻辑。
The aplication logic goes in the controllers. 应用程序逻辑进入控制器。 Aviod putting it in the templates.
Aviod把它放在模板中。
Example: 例:
template 模板
<div ng-app="myApp">
<div ng-controller="MyCtrl">
<button ng-click="btn_save()">Save</button>
<button ng-click="btn_update()">update</button>
</div>
controller 调节器
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.btn_save = function(){
alert("Button save clicked!")
}
}
Is here, in the controller where you will implement the btn_save logic. 在这里,您将在控制器中实现btn_save逻辑。 In this case, the function throw an alert dialog when user clicks on button.
在这种情况下,当用户单击按钮时,该函数会抛出一个警告对话框。
Here is the fiddle https://jsfiddle.net/xeq23e19/ 这是小提琴https://jsfiddle.net/xeq23e19/
Hope that helps. 希望有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.