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

今天小编就为大家分享一篇解决angularjs service中依赖注入$scope报错的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

控制台错误提示

ionic.bundle.js:26794 Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- DutylogService $injector/unpr?p0=<ion-nav-view nav-view="active" nav-view-transition="ios">copeProvider%20%3C-%20%24scope%20%3C-%20DutylogService at :8100/lib/ionic/js/ionic.bundle.js:13438:12 at :8100/lib/ionic/js/ionic.bundle.js:17788:19 at Object.getService [as get] (:8100/lib/ionic/js/ionic.bundle.js:17941:39) at :8100/lib/ionic/js/ionic.bundle.js:17793:45 at getService (:8100/lib/ionic/js/ionic.bundle.js:17941:39) at injectionArgs (:8100/lib/ionic/js/ionic.bundle.js:17965:58) at Object.instantiate (:8100/lib/ionic/js/ionic.bundle.js:18007:18) at Object.<anonymous> (:8100/lib/ionic/js/ionic.bundle.js:17850:24) at Object.invoke (:8100/lib/ionic/js/ionic.bundle.js:17995:19) at Object.enforcedReturnValue [as $get] (: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报错的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/8518d0c1ee986c0e0535a2ea125bfee5.html