ng-click指令的内部模板中未提供该功能 [英] ng-click in the inner template of the directive is not providing the functionality

查看:41
本文介绍了ng-click指令的内部模板中未提供该功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ng-click不提供警报.单击指令的内部模板时,不会显示警告框.

ng-click is not providing alert. When the inner template of the directive is clicked alert box is not shown.

小提琴链接在这里: http://jsfiddle.net/NNDhX/

推荐答案

您的指令具有自己的隔离范围.因此,函数"hi"应在指令的范围内.如果要传递控制器的功能,则应进行绑定,例如scope: { ..., hi: '&' }然后是<you-directive hi='hi' ..>.这是有关此文档的链接:了解包含和作用域.

Your directive has its own isolated scope. So function 'hi' should be inside directive's scope. If you want to pass your controller's function you should do binding, like scope: { ..., hi: '&' } and then <you-directive hi='hi' ..>. Here is a link to documentation about this: Understanding Transclusion and Scopes.

因此只需将其添加到链接功能中就足够了:

So just adding it in linking function is enough:

  link: function(scope, element, attrs) {
  scope.hi = function() { alert("hi"); }

此处更新了小提琴: http://jsfiddle.net/GwBAh/

这篇关于ng-click指令的内部模板中未提供该功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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