我正在测试一个简单的角度代码,但是我收到了以下错误。
错误:[$ injector:unpr]未知提供者:pServiceProvider< - pService
以下是详细信息:
ProdModule.JS
var sapp = angular.module('productsApp', []);
ProdController.js
/// <reference path="../angular.js" />
/// <reference path="ProdModule.js" />
sapp.controller('ProductsController', function productsController($scope,
pService) {
$scope.products = pService();
});
ProdService.js
/// <reference path="../angular.js" />
/// <reference path="ProdModule.js" />
// register the service
sapp.service('pService', function pService() {
return function getProducts() {
return [{ name: 'Chai' }, { name: 'Syrup' }];
}
});
Test.JS
/// <reference path="../jasmine/jasmine.js" />
/// <reference path="../dependencies/ProdModule.js" />
/// <reference path="../dependencies/ProdService.js" />
/// <reference path="../dependencies/ProdController.js" />
describe('Prod', function () {
beforeEach(module('productsApp'));
var $controller;
beforeEach(inject(function (_$controller_) {
$controller = _$controller_;
console.log($controller)
}));
it('should return products list on load', function () {
var $scope = {};
var productsController = $controller(function inlineController($scope,
pService) {
$scope.products = pService();
}, { $scope: $scope });
expect($scope.products).toEqual([{ name: 'Chai' }, { name: 'Syrup' }]);
});
})
当我将服务代码放在ProdController.js中时,它可以很好地工作,但是当我将代码分隔到每个js文件中时,测试就会中断。我可以知道我错过了什么吗?