I was having problem when updating my list to ng-repeat in view and $scope.$apply came to the rescue. I am concerned about the watchers. Is it a good practice to use $scope.$apply() frequently? Since I am having many views in application which must be updated immediately on button click.
PS: Any alternatives are appreciated.
Sample JS code of my application:
function onRefreshList() {
vm.showLoader = true;
GetDataService.getVotes(someParams).then(function(res) {
if (res){
vm.showLoader = false;
vm.voteList = res; //voteList will be updated on click of Refresh list
$scope.$apply(); //working fine with this }
}).catch(function (res) {
vm.showLoader = false;
console.log("There was an error will loading votes");
})
}
HTML:
<div ng-show="showLoader">
<ion-spinner icon="android" class="spinner-assertive"></ion-spinner>
</div>
<div ng-show="!showLoader" ng-repeat="vote in votesCtrl.voteList">
{{vote}}
</div>