【发布时间】:2013-06-26 18:36:04
【问题描述】:
我正在尝试为 AngularJS 指令编写单元测试,该指令使用与页面上的控制器不同的控制器。但是,我在测试中找不到任何方法来访问该控制器。
这是我的指令:
'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?或者有没有更好的方法来构造我的代码以便可以访问它?
【问题讨论】:
标签: angularjs angularjs-directive