解決angularjs service中依賴注入$scope報(bào)錯(cuò)的問題
控制臺(tái)錯(cuò)誤提示
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報(bào)錯(cuò)的問題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
angularjs實(shí)現(xiàn)簡(jiǎn)單的購(gòu)物車功能
這篇文章主要為大家詳細(xì)介紹了angularjs實(shí)現(xiàn)簡(jiǎn)單的購(gòu)物車功能 ,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-09-09通過AngularJS實(shí)現(xiàn)圖片上傳及縮略圖展示示例
本篇文章主要介紹了通過AngularJS實(shí)現(xiàn)圖片上傳及縮略圖展示,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧2017-01-01angularjs指令中的compile與link函數(shù)詳解
這篇文章主要介紹了angularjs指令中的compile與link函數(shù)詳解,本文同時(shí)訴大家complie,pre-link,post-link的用法與區(qū)別等內(nèi)容,需要的朋友可以參考下2014-12-12AngularJS實(shí)現(xiàn)的輸入框字?jǐn)?shù)限制提醒功能示例
這篇文章主要介紹了AngularJS實(shí)現(xiàn)的輸入框字?jǐn)?shù)限制提醒功能,涉及AngularJS事件監(jiān)聽與元素屬性動(dòng)態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-10-10在angularJs中進(jìn)行數(shù)據(jù)遍歷的2種方法
今天小編就為大家分享一篇在angularJs中進(jìn)行數(shù)據(jù)遍歷的2種方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧2018-10-10Angular.js中用ng-repeat-start實(shí)現(xiàn)自定義顯示
大家都知道Angular.js可以用ng-repeat來(lái)顯示列表數(shù)據(jù),可是如果想要自定義顯示數(shù)據(jù)列表的話ng-repeat就實(shí)現(xiàn)不了了,這個(gè)時(shí)候可以利用ng-repeat-start 和 ng-repeat-end來(lái)實(shí)現(xiàn),下面通過本文來(lái)詳細(xì)看看實(shí)現(xiàn)的方法吧。2016-10-10