Previously, the data was stored in the controller, and if they were not updated themselves - wrote

$scope.$apply ( function (results) { $scope.resers = results; }); 

Now I transferred the code to the service, but the updated data is not visible in the view. The "implement" $scope service does not want to be scolded.

What to do to see the changed data?

  • one
    I recently studied angular, and to be honest, feelings are twofold, it speeds up development several times, but its ideology wants the best. But this is irrelevant and it is possible that the articles about him are written mostly by translators, not programmers. As for you, so from the point of view of "correctness", the data should not be updated. Ideally, the service should return the value after the arguments are processed. And the Osprey is not the place in the service. - vas
  • @TwoRS code can provide? To make it clearer what was the matter. - Alliswell

1 answer 1

In general, although not necessary, $ scope should not be used in the service. Typically, a callback is sent, which is handled in the controller. Those. $scope.$apply() is called in its scope.

 var app = angular.module('app', []) .controller('Ctrl', ['$scope', 'fctry', function($scope, fctry) { var callBack = function(data) { $scope.$apply(function() { $scope.data = data; }); } $scope.get = function() { fctry(callBack); }; }]) .factory('fctry', function() { return function(callBack) { superAsyncFunction.success(callBack); }; }); 

Materials for full immersion (except official documentation):