【发布时间】:2013-03-14 19:37:43
【问题描述】:
来自 Angular docs:
& 或 &attr - 提供一种在父作用域的上下文中执行表达式的方法。如果未指定 attr 名称,则假定属性名称与本地名称相同。给定范围的小部件定义:{ localFn:'&myAttr' },则隔离范围属性 localFn 将指向 count = count + value 表达式的函数包装器。
这给我的印象是这样的事情应该是可能的,但它不起作用。我做错了什么?
myApp.directive('test', function () {
return {
restrict: 'E',
replace: true,
template: '<div><input type="button" ng-click="thefunc()" value="{{title}}"/></div>',
scope: {
title: '@',
thefunc: '&'
}
};});
HTML:
<test thefunc="alert('Here you go.')" title="Click me for a popup"/>
【问题讨论】:
标签: angularjs angularjs-directive