如何解决angularjs service中依赖注入$scope报错的问题
短信预约 -IT技能 免费直播动态提醒
小编给大家分享一下如何解决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报错的问题”有了一定的了解,如果想了解更多相关知识,欢迎关注编程网行业资讯频道,感谢各位的阅读!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341