2016-07-23 81 views
0

我不能夠通過標識在我的模式,這使得我不可能通過數據

Controller.js

app.controller('faq', function ($scope, faqservice, $ionicModal) { 
    $scope.faq = faqservice; 
    console.log($scope.faq); //upto this everything i working properly and i am able to render in my HTML page ! 

    $ionicModal.fromTemplateUrl('templates/faqDetails.html', { 
    scope: $scope 
    }).then(function (modal) { 
    $scope.faqDetails = modal; 
    }); 

    // Triggered in the FAQ detail modal to close it 
    $scope.faqClose = function() { 
    $scope.faqDetails.hide(); 
    }; 
    // Open the FAQ detail modal 
    $scope.faqOpen = function (id) { 
    $scope.faqDetails.show(); 
    $scope.notes = faqservice.getid(id); 
    console.log($scope.notes); //**i am geting this null.. and when i console.log() in getID method in service my for loop is not executing ** 
    }; 
}); 

Service.js

app.service("faqservice", function ($q, $http,Events,$ionicPopup) { 
    var self = { 
    'results': [], 
    getid: function (id) { 
     for (var i = 0; i < self.results.length; i++) { 
     if (self.results[i].id === parseInt(id)) { 
      return self.results[i]; 
     } 
     } 
     return null; 
    }, 
    'load': function() { 
     $http.get(Events.url +"/faqs") 
     .then(function (response) { 
      angular.forEach(response.data, function (data) { 
      self.results.push(data); 
      window.localStorage.setItem("faqs", JSON.stringify(data)); 
      }); 
     } 
     ,function (data) { 
      $ionicPopup.alert({ 
      title: 'Slow Internet connection', 
      template: 'Please check your internet connection for updates !' 
      }); 
      if (window.localStorage.getItem("faqs") !== undefined) { 
      self.results.push(JSON.parse(window.localStorage.getItem("faqs"))); 
      } 
     }); 

    } 
    }; 
    self.load(); 

    return self; 
}); 

*當我的互聯網連接關閉時,我的錯誤回調不起作用!我沒有收到錯誤通知我的互聯網連接關閉*

I am Getting My $scope.notes null pls help me with this issue !! 

and I am really new to Angular.js and ionic so can u pls suggest me what to 

使用成功()或然後()使用HTTP?

+0

如果你在'for循環之前'console.log(self.results.length)? – Manwal

回答

1

如果你在for循環之前?

而我認爲success()方法$http已被棄用。

+0

它應該是評論而不是發佈。你可以刪除它。歡迎來到SO! – Manwal

+0

現在我不能評論,我想開始給,所以我能做什麼? – daymosik

+0

我得到了corrct結果,當我console.log(長)! –