Ok..so看起来我通过将回调函数一直传递到resource.query()调用解决了问题。仍不确定这是否是最佳方法。
供参考,这是我所做的:
CountryController:
$scope.countries = CountryService.getCountries(function(){ //preselected default $scope.selected.country = $scope.countries[0]; });
CountryService:
//Country Service. Will contain all relevant rest methods hereservices.factory('CountryService', function($resource) { var countryService = {}; var data; var resource = $resource('http://localhost:port/restwrapper/country.json', {port: ':8080'}); var countries = function(callback) { data = resource.query(callback); return data; } return { getCountries: function(callback) { if(data) { console.log("returning cached data"); return data; } else { console.log("getting countries from server"); return countries(callback); } } }; });
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)