我正在尝试做一个小的测试工作来验证控制器是否已定义。
我收到的错误是:
myApp.orders module Order controller should .... FAILED
Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- OrdersCtrl
阅读类似的错误,它是与依赖关系,但我不知道什么是错。
控制器:
'use strict';
angular.module('myApp.orders', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/orders', {
templateUrl: 'orders/orders.template.html',
controller: 'OrdersCtrl'
});
}])
.controller('OrdersCtrl', function($scope, $location) {
$scope.changeView = function(view){
$location.path(view); // path not hash
}
});
测试:
'use strict';
describe('myApp.orders module', function() {
beforeEach(module('myApp.orders'));
describe('Order controller', function(){
it('should ....', inject(function($controller) {
//spec body
var OrdersCtrl = $controller('OrdersCtrl');
expect(OrdersCtrl).toBeDefined();
}));
});
});
这不应该是这样,但你可以.controller( 'OrdersCtrl',[ '$范围', '$位置',功能尝试( $ scope,$ location){ $ scope.changeView = function(view){ $ location.path(view); // path not hash } }]); – Indra