0

我有一个 AngularJS 指令,它从它的属性中读取输入数据,如下所示:

<my-directive input-data='items'></my-directive>

我的指令:

return {

    scope: {
        inputData: '='
    }

}
...

现在,我通常在我的作用域中定义一个嵌套的对象数组,并且指令从我的作用域中读取该数据,但现在我试图让 jasmine、grunt 和 angular 与我的指令很好地配合,以便我可以测试它,但我我收到此错误:

Error: [$compile:nonassign] Expression 'undefined' used with directive 'angularMultiSelect' is non-assignable!

这就是我试图在我的茉莉花测试中注入数据的方式:

inject(function($compile, $rootScope) {
    scope = $rootScope.$new();

    //scope.items = [];  //<--- this works, but it's useless
    scope.items = [{}, {}];  //<---- this triggers the error (I haven't deleted anything, that is an array with 2 empty objects
    elem = angular.element(html);
    $compile(elem)(scope);
    scope.$digest();
});

我应该如何将我的数据从茉莉花传递给我的指令?

4

1 回答 1

0

我的问题是该指令试图将另一个模型数据绑定到 jasmine 范围内不存在的变量。

于 2015-06-01T07:52:23.827 回答