0

我想使用解決方案。我需要從加載控制器和視圖之前的服務獲取數據。我發現了一些如何使用解決方案。爲什麼我在使用angular js中的解析時出錯?

我在項目中沒有得到錯誤,當我刪除決心聲明

.state('a', { 
     url: "/a", 
     templateUrl: "a.html", 
      controller: 'a', 
      // resolve:{ 
      // messsage:function(testservice){ 
      //  return testservice.getdata(); 
      // } 
      //} 
     }) 

當我取消的決心聲明我得到這個錯誤

**Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting! 
Watchers fired in the last 5 iterations: [] 
http://errors.angularjs.org/1.3.13/$rootScope/infdig?p0=10&p1=%5B%5D 
    at REGEX_STRING_REGEXP (ionic.bundle.js:8762) 
    at Scope.promises.$get.Scope.$digest (ionic.bundle.js:22980) 
    at Scope.promises.$get.Scope.$apply (ionic.bundle.js:23205) 
    at done (ionic.bundle.js:18358) 
    at completeRequest (ionic.bundle.js:18548) 
    at XMLHttpRequest.requestLoaded (ionic.bundle.js:18489)(anonymous function) @ ionic.bundle.js:20306jqNodes.$get @ ionic.bundle.js:17256promises.$get.Scope.$apply @ ionic.bundle.js:23207done @ ionic.bundle.js:18358completeRequest @ ionic.bundle.js:18548requestLoaded @ ionic.bundle.js:18489 
ionic.bundle.js:8762 Uncaught Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting! 
Watchers fired in the last 5 iterations: [] 
http://errors.angularjs.org/1.3.13/$rootScope/infdig?p0=10&p1=%5B%5DREGEX_STRING_REGEXP @ ionic.bundle.js:8762promises.$get.Scope.$digest @ ionic.bundle.js:22980promises.$get.Scope.$apply @ ionic.bundle.js:23205done @ ionic.bundle.js:18358completeRequest @ ionic.bundle.js:18548requestLoaded @ ionic.bundle.js:18489 
ionic.bundle.js:20306 Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting! 
Watchers fired in the last 5 iterations: [] 
http://errors.angularjs.org/1.3.13/$rootScope/infdig?p0=10&p1=%5B%5D 
    at REGEX_STRING_REGEXP (ionic.bundle.js:8762) 
    at Scope.promises.$get.Scope.$digest (ionic.bundle.js:22980) 
    at Scope.promises.$get.Scope.$apply (ionic.bundle.js:23205) 
    at done (ionic.bundle.js:18358) 
    at completeRequest (ionic.bundle.js:18548) 
    at XMLHttpRequest.requestLoaded** 

這裏是我的代碼 http://plnkr.co/edit/fk7IGcYlDfZasWqzy31S?p=preview

我想在使用控制器之前加載服務中的數據,然後加載到查看

+0

你在你的索引頁面腳本調用中使用'angular.min.js'還是完整'angular.js'? –

+0

我創建了類似的例子,它顯示瞭解決方案http://plnkr.co/edit/iY0sCnM5dzvassz2k0KL?p=preview –

回答

1

使用良好的語法爲您服務

factory('testservice', ['$http', 
    function testservice($http) { 

獲取數據在你的控制器:

$scope.data = testservice.getdata(); 

的plnk: http://plnkr.co/edit/2EskRAzVPo8lhXyaLFuy?p=preview

那麼你應該考慮在服務支持您的數據所以你一次撥打$http.get("data.json")

+0

我不想在控制器中獲取數據,我想使用解決方案。 – Shruti

+0

所以不要:http://plnkr.co/edit/ndCKijmr8SHpf0mFrd5J?p=preview –

+0

感謝您回答如何在控制器中使用這些數據..?意味着我想打電話給服務使用解決方案,並使用控制器中的兒子數據 – Shruti

相關問題