解决angularjs service中依赖注入$scope报错的问题

编程学习 2021-07-04 16:46www.dzhlxh.cn编程入门
今天长沙网络推广就为大家分享一篇解决angularjs service中依赖注入$scope报错的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随长沙网络推广过来看看吧

控制台错误提示

ionic.bundle.js:26794 Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- DutylogService
 http://errors.angularjs.org/1.5.3/$injector/unpr?p0=<ion-nav-view name="tab-dutylog" class="view-container tab-content" nav-view="active" nav-view-transition="ios">copeProvider%20%3C-%20%24scope%20%3C-%20DutylogService
 at http://localhost:8100/lib/ionic/js/ionic.bundle.js:13438:12
 at http://localhost:8100/lib/ionic/js/ionic.bundle.js:17788:19
 at Object.getService [as get] (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17941:39)
 at http://localhost:8100/lib/ionic/js/ionic.bundle.js:17793:45
 at getService (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17941:39)
 at injectionArgs (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17965:58)
 at Object.instantiate (http://localhost:8100/lib/ionic/js/ionic.bundle.js:18007:18)
 at Object.<anonymous> (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17850:24)
 at Object.invoke (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17995:19)
 at Object.enforcedReturnValue [as $get] (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17834:37) 

原因:

angular.module('myModule', [])
.service('MyController', ['$scope', function($scope) {
 // This controller throws an unknown provider error because
 // a scope object cannot be injected into a service.
}]);

建议方式:

.service('DutylogService', [function(){
 
}])

以上这篇解决angularjs service中依赖注入$scope报错的问题就是长沙网络推广分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持狼蚁SEO。

Copyright © 2016-2025 www.dzhlxh.cn 金源码 版权所有 Power by

网站模板下载|网络推广|微博营销|seo优化|视频营销|网络营销|微信营销|网站建设|织梦模板|小程序模板