解决angularjs service中依赖注入$scope报错的问题
更新时间:2018年10月02日 16:10:23 作者:飞向Hadoop
今天小编就为大家分享一篇解决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报错的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
Angular.js 4.x中表单Template-Driven Forms详解
Angular 4.x 中有两种表单,一种是Template-Driven Forms - 模板驱动式表单,另外一种是Reactive Forms - 响应式表单 ,下面这篇文章主要给大家介绍了Angular.js 4.x中表单Template-Driven Forms的相关资料,需要的朋友可以参考学习,下面来一起看看吧。2017-04-04AngularJS使用ui-route实现多层嵌套路由的示例
这篇文章主要介绍了AngularJS使用ui-route实现多层嵌套路由的示例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧2018-01-01Angular实现的内置过滤器orderBy排序与模糊查询功能示例
这篇文章主要介绍了Angular实现的内置过滤器orderBy排序与模糊查询功能,涉及AngularJS过滤器、排序及字符串遍历、查询等相关操作技巧,需要的朋友可以参考下2017-12-12详解Angular.js数据绑定时自动转义html标签及内容
本篇文章主要介绍了详解Angular.js数据绑定时自动转义html标签及内容 ,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。2017-03-03
最新评论