像这样的函数:ng-click =" alert('Clicked')' [英] A function like: ng-click="alert('Clicked')"

查看:154
本文介绍了像这样的函数:ng-click =" alert('Clicked')'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于模型,我需要一个简单的机制,例如

For a mockup I need a simple mechanism like

ng-click="alert('Clicked')"

但是上面的代码不起作用,有人可以帮我吗?我不想触摸控制器.

but the code above is not working, can someone help me? I don't want to touch the Controller..

推荐答案

据我所知,ng-click仅在您的$scope中起作用.因此,您只能调用在$scope本身中定义的函数.要使用警报,您可以尝试使用window.alert('Clicked')来访问window元素.

As far as I know, ng-click works only within your $scope. So you would only be able to call functions, defined in your $scope itself. To use alert, you may try accessing the window element, just by using window.alert('Clicked').

EIDT :感谢易卜拉欣.我忘了.就您将无法定义的范围而言,您应该不能使用window.alert:

EIDT: Thanks to Ibrahim. I forgot. You shouldn't be able to use window.alert, as far as you won't define:

$scope.alert = window.alert;

在这种情况下,应该在ng-clicked指令中使用alert('Clicked').但是最后,这种方法无法解决您不碰控制器的问题.

In this case, using alert('Clicked') in your ng-clicked directive should work. But at the end, this method would not solve your problem of not touching your controller.

这篇关于像这样的函数:ng-click =" alert('Clicked')'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆