Angular.provider 未知
Angular.provider Unknown
你好,我在尝试解决 "unknown provider"
时遇到了一些问题,我分享了一些代码,以便你可以帮助我找出问题所在:
angular
.module('ngNewDrupal', ['ng', 'ngResource'])
.provider('$newDrupal', function() {
var provider = this;
this.defaults = { [...]
};
this.$get = ['$log', '$resource', function ($log, $resource) {
var forEach = angular.forEach;
function getResource(name, params) {
/*switch (name) {
}*/
}
function getRoute(url) {
return provider.defaults.host + url;
}
var NewDrupal = function () {
};
[...]
return NewDrupal;
}];
});
})(window, window.angular);
在 index.module.js 我添加了 ngNewDrupal 到
angular
.module('app', [
进入我的xxx.components.js我举个例子
angular
.module('app')
.component('rendition', rendition());
function rendition() {
return {
templateUrl: 'app/components/rendition/rendition.html',
controller: renditionController,
controllerAs: 'rd'
};
function renditionController($log, $newDrupal, $stateParams, $http) {
var rd = this;
var Drupal = new $newDrupal();
最后我通过 'xxx.config.js' 像
向我的 $newDrupal 添加了一些操作
angular
.module('app')
.config(config);
function config($newDrupal) {
$newDrupal.defaults.actions.getMyPublication = {
webservice: { url: '/export_rest/my_publication' },
type: 'GET',
params: {
_format: 'json',
cache: true,
isArray: true
}
};
但是它发送给我:
angular.js:68 Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [$injector:unpr] Unknown provider: $newDrupal
http://errors.angularjs.org/1.5.8/$injector/unpr?p0=%24newDrupal
at http://192.168.50.100:3000/bower_components/angular/angular.js:68:12
at http://192.168.50.100:3000/bower_components/angular/angular.js:4511:19
at getService (http://192.168.50.100:3000/bower_components/angular/angular.js:4664:39)
at injectionArgs (http://192.168.50.100:3000/bower_components/angular/angular.js:4688:58)
at Object.invoke (http://192.168.50.100:3000/bower_components/angular/angular.js:4710:18)
at runInvokeQueue (http://192.168.50.100:3000/bower_components/angular/angular.js:4611:35)
at http://192.168.50.100:3000/bower_components/angular/angular.js:4620:11
at forEach (http://192.168.50.100:3000/bower_components/angular/angular.js:321:20)
at loadModules (http://192.168.50.100:3000/bower_components/angular/angular.js:4601:5)
at createInjector (http://192.168.50.100:3000/bower_components/angular/angular.js:4523:19)
http://errors.angularjs.org/1.5.8/$injector/modulerr?p0=app&p1=Error%3A%20%…92.168.50.100%3A3000%2Fbower_components%2Fangular%2Fangular.js%3A4523%3A19)
at http://192.168.50.100:3000/bower_components/angular/angular.js:68:12
at http://192.168.50.100:3000/bower_components/angular/angular.js:4511:19
at getService (http://192.168.50.100:3000/bower_components/angular/angular.js:4664:39)
at injectionArgs (http://192.168.50.100:3000/bower_components/angular/angular.js:4688:58)
at Object.invoke (http://192.168.50.100:3000/bower_components/angular/angular.js:4710:18)
at runInvokeQueue (http://192.168.50.100:3000/bower_components/angular/angular.js:4611:35)
at http://192.168.50.100:3000/bower_components/angular/angular.js:4620:11
at forEach (http://192.168.50.100:3000/bower_components/angular/angular.js:321:20)
at loadModules (http://192.168.50.100:3000/bower_components/angular/angular.js:4601:5)
at createInjector (http://192.168.50.100:3000/bower_components/angular/angular.js:4523:19)
http://errors.angularjs.org/1.5.8/$injector/modulerr?p0=app&p1=Error%3A%20%…92.168.50.100%3A3000%2Fbower_components%2Fangular%2Fangular.js%3A4523%3A19)
at http://192.168.50.100:3000/bower_components/angular/angular.js:68:12
at http://192.168.50.100:3000/bower_components/angular/angular.js:4640:15
at forEach (http://192.168.50.100:3000/bower_components/angular/angular.js:321:20)
at loadModules (http://192.168.50.100:3000/bower_components/angular/angular.js:4601:5)
at createInjector (http://192.168.50.100:3000/bower_components/angular/angular.js:4523:19)
at doBootstrap (http://192.168.50.100:3000/bower_components/angular/angular.js:1758:20)
at bootstrap (http://192.168.50.100:3000/bower_components/angular/angular.js:1779:12)
at angularInit (http://192.168.50.100:3000/bower_components/angular/angular.js:1664:5)
at HTMLDocument.<anonymous> (http://192.168.50.100:3000/bower_components/angular/angular.js:31763:5)
at fire (http://192.168.50.100:3000/bower_components/jquery/dist/jquery.js:3187:31)
我没有找到需要修改的内容和位置。
正确答案是更改
function config($newDrupal)
进入
function config($newDrupalProvider)
在每个 xxx.config.js 文件中。
你好,我在尝试解决 "unknown provider"
时遇到了一些问题,我分享了一些代码,以便你可以帮助我找出问题所在:
angular
.module('ngNewDrupal', ['ng', 'ngResource'])
.provider('$newDrupal', function() {
var provider = this;
this.defaults = { [...]
};
this.$get = ['$log', '$resource', function ($log, $resource) {
var forEach = angular.forEach;
function getResource(name, params) {
/*switch (name) {
}*/
}
function getRoute(url) {
return provider.defaults.host + url;
}
var NewDrupal = function () {
};
[...]
return NewDrupal;
}];
});
})(window, window.angular);
在 index.module.js 我添加了 ngNewDrupal 到
angular
.module('app', [
进入我的xxx.components.js我举个例子
angular
.module('app')
.component('rendition', rendition());
function rendition() {
return {
templateUrl: 'app/components/rendition/rendition.html',
controller: renditionController,
controllerAs: 'rd'
};
function renditionController($log, $newDrupal, $stateParams, $http) {
var rd = this;
var Drupal = new $newDrupal();
最后我通过 'xxx.config.js' 像
向我的 $newDrupal 添加了一些操作angular
.module('app')
.config(config);
function config($newDrupal) {
$newDrupal.defaults.actions.getMyPublication = {
webservice: { url: '/export_rest/my_publication' },
type: 'GET',
params: {
_format: 'json',
cache: true,
isArray: true
}
};
但是它发送给我:
angular.js:68 Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [$injector:unpr] Unknown provider: $newDrupal
http://errors.angularjs.org/1.5.8/$injector/unpr?p0=%24newDrupal
at http://192.168.50.100:3000/bower_components/angular/angular.js:68:12
at http://192.168.50.100:3000/bower_components/angular/angular.js:4511:19
at getService (http://192.168.50.100:3000/bower_components/angular/angular.js:4664:39)
at injectionArgs (http://192.168.50.100:3000/bower_components/angular/angular.js:4688:58)
at Object.invoke (http://192.168.50.100:3000/bower_components/angular/angular.js:4710:18)
at runInvokeQueue (http://192.168.50.100:3000/bower_components/angular/angular.js:4611:35)
at http://192.168.50.100:3000/bower_components/angular/angular.js:4620:11
at forEach (http://192.168.50.100:3000/bower_components/angular/angular.js:321:20)
at loadModules (http://192.168.50.100:3000/bower_components/angular/angular.js:4601:5)
at createInjector (http://192.168.50.100:3000/bower_components/angular/angular.js:4523:19)
http://errors.angularjs.org/1.5.8/$injector/modulerr?p0=app&p1=Error%3A%20%…92.168.50.100%3A3000%2Fbower_components%2Fangular%2Fangular.js%3A4523%3A19)
at http://192.168.50.100:3000/bower_components/angular/angular.js:68:12
at http://192.168.50.100:3000/bower_components/angular/angular.js:4511:19
at getService (http://192.168.50.100:3000/bower_components/angular/angular.js:4664:39)
at injectionArgs (http://192.168.50.100:3000/bower_components/angular/angular.js:4688:58)
at Object.invoke (http://192.168.50.100:3000/bower_components/angular/angular.js:4710:18)
at runInvokeQueue (http://192.168.50.100:3000/bower_components/angular/angular.js:4611:35)
at http://192.168.50.100:3000/bower_components/angular/angular.js:4620:11
at forEach (http://192.168.50.100:3000/bower_components/angular/angular.js:321:20)
at loadModules (http://192.168.50.100:3000/bower_components/angular/angular.js:4601:5)
at createInjector (http://192.168.50.100:3000/bower_components/angular/angular.js:4523:19)
http://errors.angularjs.org/1.5.8/$injector/modulerr?p0=app&p1=Error%3A%20%…92.168.50.100%3A3000%2Fbower_components%2Fangular%2Fangular.js%3A4523%3A19)
at http://192.168.50.100:3000/bower_components/angular/angular.js:68:12
at http://192.168.50.100:3000/bower_components/angular/angular.js:4640:15
at forEach (http://192.168.50.100:3000/bower_components/angular/angular.js:321:20)
at loadModules (http://192.168.50.100:3000/bower_components/angular/angular.js:4601:5)
at createInjector (http://192.168.50.100:3000/bower_components/angular/angular.js:4523:19)
at doBootstrap (http://192.168.50.100:3000/bower_components/angular/angular.js:1758:20)
at bootstrap (http://192.168.50.100:3000/bower_components/angular/angular.js:1779:12)
at angularInit (http://192.168.50.100:3000/bower_components/angular/angular.js:1664:5)
at HTMLDocument.<anonymous> (http://192.168.50.100:3000/bower_components/angular/angular.js:31763:5)
at fire (http://192.168.50.100:3000/bower_components/jquery/dist/jquery.js:3187:31)
我没有找到需要修改的内容和位置。
正确答案是更改
function config($newDrupal)
进入
function config($newDrupalProvider)
在每个 xxx.config.js 文件中。