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';
}])


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM