angularjs - Data assign through service not updating in Angular JS -
angularjs - Data assign through service not updating in Angular JS -
i wrote service share , update datas between controller
myapp.service('physician',function($http){ var physicians = []; var refresh = function(fetch) { physicians = [] $http({ url: '/provider/', method: 'get', }).success(function (response) { $.each(response, function(index, value){ physicians.push(value); }); console.log(physicians); }); } homecoming { refresh: refresh, all: physicians }; })
i included above service in controller
function physiciancontroller($scope, $http, physician) { $scope.physicians = physician.all }
now have controller sharing physician service , calling refresh function in it.
function conditioncontroller($scope, $http, physician) { $scope.add = function() { physician.refresh(); } }
as refresh function called expect $scope.physicians in physiciancontroller updated, not , tips helpful.
@sergiu paraschiv's reply : physicians = [] assigns new reference physicians variable. angularjs relies on maintain same reference able maintain track of changes. need empty array, not reinitialize it. a.splice(0,a.length) should work
angularjs angularjs-directive angularjs-scope angularjs-ng-repeat angular-services
Comments
Post a Comment