绑定函数通过嵌套指令与孤立范围在Angular 1.4中失败

And*_*nes 4 angularjs angular-directive

在嵌套指令中绑定函数时,1.4更新似乎引入了一个问题.我有一个示例plunker:http://plnkr.co/edit/fQLY0N8BTNs38VC8ikll

码:

var app = angular.module('myApp', []);

app.controller('myCtrl', function(){
  this.searchFunction = function(term) {
    console.log('you searched for ' + term);
  }
 });

 app.directive('outerDirective', function(){
   return {
    restrict: 'E',
    scope: {
      outer: '&'
    },
    template: '<inner-directive inner="cx.outer(term)"></inner-directive>',
    controller: function(){

    },
    controllerAs: 'cx',
    bindToController: true
  };
});

app.directive('innerDirective', function(){
  return {
    restrict: 'E',
    scope: {
      inner: '&'
    },
    template: '<a ng-click="cx.execute()">Click</a>',
    controller: function(){
      this.execute = function(){
        this.inner('fred');
      }
    },
    controllerAs: 'cx',
    bindToController: true
  };
});
Run Code Online (Sandbox Code Playgroud)

这是在1.3中工作,但在1.4中我应该采用一些新方法吗?

单击该链接,您将在控制台中看到以下错误:

TypeError:不能使用'in'运算符在fn中搜索fred中的'cx'(eval at(https://code.angularjs.org/1.4.0/angular.js:13036:15),:2:54)在目的地.(匿名函数)[内部](https://code.angularjs.org/1.4.0/angular.js:8689:22)执行时(http://run.plnkr.co/zE9xlCQNMBrOZZgi/script .js:35:14)at fn(eval at(https://code.angularjs.org/1.4.0/angular.js:13036:15),:2:237)回调(https:// code. angularjs.org/1.4.0/angular.js:23090:17)在Scope.$ eval(https://code.angularjs.org/1.4.0/angular.js:15719:28)的Scope.$ apply(https://code.angularjs.org/1.4.0/angular.js:15818:23)在HTMLAnchorElement.(https://code.angularjs.org/1.4.0/angular.js:23095:23)在HTMLAnchorElement.eventHandler(https://code.angularjs.org/1.4.0/angular.js:3247:21)

spi*_*eap 14

看起来您遇到了错误,因为您没有使用该{param: value}方法来调用指令中的函数.plunkr也缺乏这个cx.outer功能,所以我不确定我们期望发生什么.

我已经更新了你的plunkr以证明它使用Angular 1.4并使用显式参数传递:http://plnkr.co/edit/T7aasD?p = preview .