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';
}])
posted @ 2016-10-24 21:10  CooMark  阅读(1873)  评论(0编辑  收藏  举报