解決angularjs service中依賴注入$scope報(bào)錯(cuò)的問(wèn)題
控制臺(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ò)的問(wèn)題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
解決Angular.Js與Django標(biāo)簽沖突的方案
AngularJS和django的模板都是用{{}}來(lái)引用變量的,這就導(dǎo)致了沖突,所以這篇文章主要就給大家介紹了如何解決Angular.Js與Django標(biāo)簽沖突的方案,有需要的朋友們可以參考借鑒,下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2016-12-12
AngularJs unit-testing(單元測(cè)試)詳解
本文主要介紹AngularJs unit-testing(單元測(cè)試)的內(nèi)容,這里整理了單元測(cè)試的知識(shí),及示例代碼,有興趣的朋友可以參考下2016-09-09
Angular實(shí)現(xiàn)下拉框模糊查詢功能示例
這篇文章主要介紹了Angular實(shí)現(xiàn)下拉框模糊查詢功能,涉及AngularJS事件響應(yīng)及字符串查詢等相關(guān)操作技巧,需要的朋友可以參考下2018-01-01
AngularJS實(shí)現(xiàn)的JSONP跨域訪問(wèn)數(shù)據(jù)傳輸功能詳解
這篇文章主要介紹了AngularJS實(shí)現(xiàn)的JSONP跨域訪問(wèn)數(shù)據(jù)傳輸功能,較為詳細(xì)的分析了JSONP的概念、功能并結(jié)合實(shí)例形式給出了AngularJS使用JSONP進(jìn)行跨域訪問(wèn)數(shù)據(jù)傳輸?shù)南嚓P(guān)技巧,需要的朋友可以參考下2017-07-07
Angular Module聲明和獲取重載實(shí)例代碼
這篇文章主要介紹了Angular Module聲明和獲取重載實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下2016-09-09
完美解決UI-Grid表格元素中多個(gè)空格顯示為一個(gè)空格的問(wèn)題
下面小編就為大家?guī)?lái)一篇完美解決UI-Grid表格元素中多個(gè)空格顯示為一個(gè)空格的問(wèn)題。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-04-04
使用Angular CLI快速創(chuàng)建Angular項(xiàng)目的一些基本概念和寫法小結(jié)
這篇文章主要介紹了使用Angular CLI快速創(chuàng)建Angular項(xiàng)目的一些基本概念和寫法小結(jié),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-04-04

