簡體   English   中英

使用隔離范圍數據測試Angular指令

[英]Testing an Angular directive with isolate scope data

我有一個AngularJS指令,該指令從其屬性讀取輸入數據,如下所示:

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

我的指令:

return {

    scope: {
        inputData: '='
    }

}
...

現在,我通常在我的作用域中定義一個嵌套的對象數組,該指令從我的作用域中讀取該數據,但是現在我正嘗試使茉莉花,咕unt聲和有角度的聲音與我的指令很好地配合,以便可以測試它,我收到此錯誤:

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();
});

我應該如何將茉莉花中的數據傳遞給指令?

我的問題是該指令試圖將另一個模型數據綁定到茉莉花范圍內的不存在的變量。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM