angular.js:13920 Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- testServe

时间:2023-11-21 13:12:02

angular.js:13920 Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- testServe

angularjs error

angular.js:13920 Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- testServe

粗线这个错误是因为往Service里面注入了不该注入的东西,service provider在DI的时候找不到合适的provider完成DI。

典型的就是往里面注入$scope, 换成$rootScope就没问题。

angular.js:13920 Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- testServe

angular.module('myapp', [])

//.service('testServe', ['$scope', function($scope) {
// console.log('xxxx: ', 3333333);
// this.name = '123';
//}]) .service('testServe2', ['$rootScope', function($rootScope) {
console.log('xxxx: ', 3333333);
this.name = '123';
}])