如何在加載視圖和控制器之前從服務中獲取數據。我做這樣的如何在控制器加載之前加載數據?
resolve: {
getAlbum: function(albumService){
return albumService.getAlbums();
},getAtum: function(albumService){
return albumService.getAtum();
}
}
我有一個服務這
.factory('albumService', ['$http', '$q'],
function albumService($http, $q) {
// interface
var service = {
albums: [],
getAlbums: getAlbums,
getAtum:getAtum
};
return service;
// implementation
function getAlbums() {
var def = $q.defer();
$http.get("data.json")
.success(function(data) {
service.albums = data;
def.resolve(data);
})
.error(function() {
def.reject("Failed to get albums");
});
return def.promise;
}
function getAtum() {
var def = $q.defer();
$http.get("data.json")
.success(function(data) {
service.albums = data;
def.resolve(data);
})
.error(function() {
def.reject("Failed to get albums");
});
return def.promise;
}
})
我需要加載此控制器和視圖之前得到服務的數據。
.controller('PlaylistsCtrl', function($scope) {
$scope.playlists = [{
title: 'Reggae',
id: 1
}, {
title: 'Chill',
id: 2
}, {
title: 'Dubstep',
id: 3
}, {
title: 'Indie',
id: 4
}, {
title: 'Rap',
id: 5
}, {
title: 'Cowbell',
id: 6
}];
})
我從兩個服務。我需要得到的數據顯示裝載機,直到我得到兩個service.I數據現在用它來顯示裝載機
http://ionicframework.com/docs/api/service/ $ ionicLoading/
Plunker http://plnkr.co/edit/4k7fliaYQx3teVH326cD?p=info
$ http傳統承諾方法的成功和錯誤已被棄用。 https://docs.angularjs.org/api/ng/service/$http – FRECIA
請提供plunker – user944513
您的運動員缺少有效的cordova.js參考 – zszep