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

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

angularjs error

粗线这个错误是因为往Service里面注入了不该注入的东西,service provider在DI的时候找不到合适的provider完成DI。
典型的就是往里面注入$scope, 换成$rootScope就没问题。

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';
}])
原文地址:https://www.cnblogs.com/wancy86/p/5994621.html