Search Posts

Category: watch

accessing directive scope variable inside the controller [duplicate]

This question already has an answer here: Bindings on directive with Isolate scope not in scope sometimes 1 answer parentData is being assigned a value in the parent controller. testDir directive is being called in the parent html. <test-dir directive-data=”parentData”></test-dir> testDir directive: app.directive(‘testDir’, function () { return { restrict: ‘E’, scope: { directiveData: ‘=’ }, controller: ‘myctrl’, templateUrl: ‘view/myView.html’ }; }); myCtrl controller: app.controller(‘myCtrl’, [‘$scope’, function($scope) { $scope.newVar = $scope.directiveData; console.log($scope.directiveData); //printing undefined. console.log($scope); //prints […]

Angularjs $watch issue on string [on hold]

I am using AngularJS in a project. What I am facing is rather strange. I have a string $scope variable and a watcher registred inside the Controller to alert me when the input field that uses that value in the ng-model, changes. The thing is that i do not get the alert. BUT…whan I use “controller As” synatax it happens to work just fine ! Any ideas ? Thanks Source: AngularJS

angular 1.5: watch doesn’t call when i toggle the ui

I my template i have: <md-checkbox ng-model=”$ctrl.isAdOps” aria-label=”isAdOps”> isAdOps {{ $ctrl.isAdOps }} </md-checkbox> In my component: (function (app) { app.component(‘homeComponent’, { templateUrl: ‘partials/home-partial.html’, bindings: { isAdOps: ‘=’ }, controller: [‘$scope’, ‘$state’, function ($scope, $state) { var self = this; $scope.$watch( self.isAdOps, function (isAdOps) { $scope.$broadcast(‘isAdOpsToggled’, isAdOps); } ); }] }); })(myApp); why doesn’t the watch called when i toggle the md-checkbox? Source: AngularJS

AngularJS $watch unbind function is not defined when being called only

I am building a user session activity timer using AngularJS 1.6. I am using $scope.$watch to monitor the value of a countdown timer. This works for the most part although $watch is binding to the variable multiple times, every time the session timer function is called. To solve this, I think I need to simply unbind the watcher if it is already defined. I saw some very simple examples on how to do this on […]

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’, […]