Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 使用'&';角度指令中的范围变量_Angularjs_Angularjs Directive - Fatal编程技术网

Angularjs 使用'&';角度指令中的范围变量

Angularjs 使用'&';角度指令中的范围变量,angularjs,angularjs-directive,Angularjs,Angularjs Directive,从角度来看: &or&attr-提供在父作用域上下文中执行表达式的方法。如果未指定属性名,则假定属性名与本地名相同。给定作用域的定义:{localFn:'&myAttr'},然后隔离作用域属性localFn将指向count=count+value表达式的函数包装器 这给我的印象是,像这样的事情应该是可能的,但它不起作用。我做错了什么 myApp.directive('test', function () { return { restrict: 'E', replace: tru

从角度来看:

&or&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: '&'
    }
};});
myApp.directive('test',function(){
返回{
限制:'E',
替换:正确,
模板:“”,
范围:{
标题:“@”,
thefunc:“&”
}
};});
HTML:


Angular正在控制器范围内寻找“警报”——

$scope.alert = function(){..}
而不是窗户

以下是更新版本:


谢谢。我想我在想它只是评估&attribute或其他东西的内容,但显然这是错误的。很容易忘记这些作用域实际上是多么孤立。
$scope.alert = function(){..}