这个错误通常发生在Angular应用程序中,表示在注入依赖项时,没有找到提供者。
解决此错误的方法是确保正确配置和注入所需的提供者。以下是一些可能的解决方法:
示例代码:
class MyController {
static $inject = ['$http'];
constructor(private $http: ng.IHttpService) {
// ...
}
}
示例代码:
angular.module('myApp')
.factory('myFactory', function() {
// ...
});
angular.module('myApp', ['otherModule'])
来加载其他模块。示例代码:
angular.module('myApp', ['otherModule']);
angular.module('myApp', ['dependencyModule'])
来加载其他模块。示例代码:
angular.module('myApp', ['dependencyModule']);
示例代码:
class MyController {
static $inject = ['$http'];
constructor(private $http: ng.IHttpService) {
// ...
}
}
通过检查以上因素,您应该能够解决“Angular 出现错误: $injector:unpr 未知提供者”的问题。
上一篇:Angular 创建遮罩层