解决angularjs service中依赖注入$scope报错的问题
程序员文章站
2022-04-09 13:57:44
控制台错误提示
ionic.bundle.js:26794 error: [$injector:unpr] unknown provider: $scopepro...
控制台错误提示
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报错的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
上一篇: 某宝上买了一箱火腿肠