Answer the question
In order to leave comments, you need to log in
How to correctly update the data in the view during operation, having the resolve option?
How to correctly update the data in the view during operation, having the resolve option, in which the initial loading is performed, without duplicating the code:
- do as in the example and simply reload the view
- select a separate procedure in the scope of the controller (or outside the scope), which is called through resolve and inside the controller?
angular.module('phonecat', ['phonecatFilters', 'phonecatServices', 'phonecatDirectives']).
config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/phones', {
templateUrl: 'partials/phone-list.html',
controller: PhoneListCtrl,
resolve: PhoneListCtrl.resolve})
}]);
function PhoneListCtrl($scope, phones) {
$scope.phones = phones;
$scope.orderProp = 'age';
}
PhoneListCtrl.resolve = {
phones: function(Phone, $q) {
var deferred = $q.defer();
Phone.query(function(successData) {
deferred.resolve(successData);
}, function(errorData) {
deferred.reject();
});
return deferred.promise;
}
}
Answer the question
In order to leave comments, you need to log in
Make a service that will perform the download, this service is injected into all the necessary places. Service methods return a promise, in fact, that's what you now have in resolve to bring to the service as a standalone function. Optionally, you can also make a service for storing downloaded elements. And you have some very old code, $resource methods already return a promise, all these deffered are not needed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question