每当我尝试向控制器和服务添加“新”功能时,都会出现此错误:错误:[$ injector:unpr]未知提供程序:companyServiceProvider <-companyService <-CompanyController
我玩了几次函数,然后奇迹般地开始工作(我最后一次所做的就是更改函数的名称)。必须有一种防止这种情况发生的方法,但是对于我的一生,我无法弄清楚。
这是我的控制器代码的片段:
myApp.controller("CompanyController", function($scope, $timeout, companyService){
$scope.SelectedCompanyId = '';
$scope.form = {};
$scope.lastState = true;
pass = 0;
$scope.addedStates = [];
getCompanies();
function getCompanies() {
companyService.getCompanies()
.success(function (data) {
$scope.companies = data;
})
.error(function (error) {
$scope.status = 'Unable to load customer data: ' + error.message;
});
};
getModules();
function getModules() {
companyService.getModules()
.success(function (data) {
$scope.modules = data;
})
.error(function (error) {
$scope.status = 'Unable to load Dashboard Modules: ' + error.message;
});
};
getModuleColors();
function getModuleColors() {
companyService.getModuleColors()
.success(function (data) {
$scope.colors = data;
})
.error(function (error) {
$scope.status = 'Unable to load Dashboard Modules: ' + error.message;
});
};
这是我的服务的摘要:
angular.module('dashboardManagement')
.service('companyService'(), [
'$http', function ($http) {
//this.selectedCompanyId = null;
this.getCompanies = function () {
return $http.get('/Home/GetAllCompanies');
};
this.getModules = function () {
return $http.get('/Home/GetDashboardModules');
};
this.getModuleColors = function () {
return $http.get('/Home/GetModuleColors');
};
this.getCurrentModules = function (companyId) {
//this.selectedCompanyId = companyId;
return $http.get('/Home/GetCurrentModules?companyId=' + companyId);
};
现在引发错误的函数是“ getModuleColors”函数,因为它是最后添加的函数。
其他功能工作正常。有人可以告诉我这是怎么回事吗?
任何帮助都将不胜感激。
这是您的代码正常工作:
https://jsfiddle.net/afv4t8h2/1/
您需要将要服务的脚本放在控制器的脚本之前,并且在代码上有一个小错误:
<li ng-repeat="region in serviceRegions">{{region.}}</li>
这是一个不间断的角度表达式...正确为{{region}}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句