1
我正在嘗試爲AngularJS指令編寫單元測試,該指令使用頁面上的單獨控制器。但是,我無法從我的測試中找到任何訪問該控制器的方法。用他們自己的控制器測試Angular指令
這裏是我的指令:
'use strict';
angular.module('myapp.directives')
.directive('searchButton', function() {
function SearchButtonCtrl ($scope, $location) {
$scope.search = function() {
$location.path('/search');
$location.search(q, $scope.query.w);
};
}
return {
template: '<input type="text" ng-model="query.q">',
controller: SearchButtonCtrl,
restrict: 'E'
};
});
是否有可能訪問SearchButtonCtrl
?還是有更好的方法來構建我的代碼,以便可以訪問它?