/ / Ako implementovať opätovné zdokonalenie iónov s $ http vypáleným z riešenia cesty - angularjs, mobilný, iónový rámec

Ako implementovať opätovné zdokonalenie iónov s $ http vypáleným z riešenia cesty - angularjs, mobile, ionic-framework

Pracujem na iontárnom projekte a získavamúdaje z API služby REST prostredníctvom služby $ http. Robím to počas riešenia v rámci cesty, ktorá prináša sľub od služby a vstrekne sa do regulátora. Moja funkcia doRefresh je v rámci tohto regulátora, avšak rozhodnutie je v rámci trasy, čo môže mať pochybnosti.

môj trasa Je tu:

.config(function($stateProvider, $urlRouterProvider) {

$stateProvider
.state("home", {
url: "/",
templateUrl: "templates/home.html",
controller: "MainCtrl as vm",
resolve: {
weather: function(MyService) {
return MyService.getData();
}
});

$urlRouterProvider.otherwise("/");
});

môj služba Je tu

.factory("MyService", function($http) {
function getData() {
return $http.get("http://something.api?format=json")
.then(function(res) {
return res.data;
});
}

return {
getData: getData()
};
});

A nakoniec tu je moje kontrolór

.controller("MainCtrl", function(weather, $ionicLoading) {

var vm = this;
vm.weather = weather;

vm.doRefresh = function() {
// how can I resolve the promise here?? It is right? Is this the correct architecture?
}

});

Vdaka za pomoc!

odpovede:

1 pre odpoveď č. 1

No, weather by mal vrátiť sľub. Môžete tak urobiť vo svojom regulátore:

vm.weather.then(function(){
...
})