[英]Test access controller in angular directive
我需要測試從控制器到指令的方法。
APP.angular.directive('miniCrud', function () {
return {
restrict: 'E',
require:"ngModel",
scope: {
miniCrudHeader: '@',
miniCrudConfig: '=',
modelValues : "=ngModel"
},
templateUrl: 'templates/mini-crud.html',
controller: ['$scope', 'lodash', 'filterFilter',
function($scope, _, filterFilter){
$scope.vm = {
getValue: function(item, index) {
var prop = $scope.miniCrudConfig.fields[index].name;
return item[prop];
}
// some other methods
}
}
}]
};
});
如何訪問$ scope.vm.getValue()?
希望您知道如何測試指令。 由於您的指令創建了隔離范圍,因此必須在angular.element返回的對象上使用isolatedScope
函數。
在測試中創建html指令元素后,對其進行編譯並將其鏈接到作用域。 然后,您可以使用已編譯的元素來獲取孤立的作用域
var s = angular.element(compiledAndLinkedDOM).isolatedScope();
s.vm.getValue();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.