Search Posts

Category: watch

Angular $watchCollection old value is not updated properly for multiple updates

I have an html file which has 3 check box values <input type=”checkbox”ng-model=”checkbox-1″/> <input type=”checkbox”ng-model=”checkbox-2″/> <input type=”checkbox”ng-model=”checkbox-3″/> and there is a watchCollection defined in the controller where it will be triggered when a checkbox status is changed $scope.$watchGroup([‘checkbox-1’, ‘checkbox-2’, ‘checkbox-3’], function (newValue, oldValue) { console.log(‘checkbox-1: new – ‘ + newValue[0] + ‘ old – ‘ + oldValue[0]); console.log(‘checkbox-1: new – ‘ + newValue[1] + ‘ old – ‘ + oldValue[1]); console.log(‘checkbox-1: new – ‘ + […]

$watch on input text is returning undefined

I am trying to use $watch in a input text. It’s returning undefined when I type for the first time, and it doesn’t work anymore when I try to type for the second time and so on. What am I doing wrong ? $scope.$watch(‘formNovoCred.dadosEC.representante.cpf’, function(newValue, oldValue) { $rootScope.formNovoCred.dadosEC.representante.cpf = $rootScope.formNovoCred.dadosEC.representante.cpf; if (newValue != oldValue){ console.log(“here”, $rootScope.formNovoCred.dadosEC.representante.cpf); } }, true); Source: AngularJS

Setting up a listener with $watch in Angular JS

I have a service making two consecutive calls to an API asynchronously. I would like the app to wait for both to be resolved before proceeding and since one of calls may or may not be made, I believe $watch is the way to go versus nested or chained callbacks. var response_complete = {call1:false, call2:false}; $“”, data, header).then(function(res){ /* … */ response_complete.call1 = true; }); if(make_this_call==true){ $“”, data, header).then(function(res){ /*…*/ response_complete.call2 = true; }); } […]

AngularJS SET service variable in controller, and use GET it everywhere else without $watch

Here is my basic service to SET and GET the value: .service(‘companyService’, [ function () { var self = this self.options = {} function CompanyService () { self.setOptions = function (newObj) { self.options = newObj } } return CompanyService() }]) In the global controller I call my $api factory which makes an http request (with promise) to get and set Company Options. I do this only once. .controller(‘global’, [‘$scope’, ‘$http’, ‘$api’, ‘$location’, ‘$translate’, ‘$rootScope’, ‘$timeout’, […]