FAQ Database Discussion Community


$rootsScope.$watch not getting triggered

angularjs,angularjs-scope,angularjs-watch
I have a watch set in a service (code snippet below) and I cannot figure out why it is not getting triggered. The a similar watch set in a controller (using $Scope.$watch) IS getting triggered when the object changes. What am I missing? (function() { 'use strict'; angular .module('evidentia') .service('srcPaneSvc',...

In angularJs: what's the different between setting $watch on string variable and setting $watch on Object's key?

angularjs,angularjs-watch
In angularJs: what's the different between setting $watch on string variable and setting $watch on Object's key? The detail scenario is as follow: $scope.activedMenu = {'id' : '...', 'name' : 'menu1'}; $scope.selectedMenuName = 'menu1'; $scope.$watch('activedMenu.name', function () {...}); $scope.$watch('selectedMenuName', function () {...}); So, my question is what's the different between...

ng-change doesn't get fired for email input unless I enter a valid email address

javascript,angularjs,angularjs-ng-change,angularjs-watch
Model value for invalid email input is always undefined. I would like to be able to check if the user has entered any text (even if it's not yet a valid email address). Please check plnkr for more details on the implementation: http://plnkr.co/edit/qV2eqGFhPvZSZKexDVF2?p=preview Html: <body ng-controller="MainCtrl"> <form> <div> <label for="email">Email...

$watch an Async Service variable doesn't work

javascript,angularjs,angularjs-watch
Hi I spent the last two days trying to make a view depending upon the response of an async http service. But it doesn't work for me. Can any one help me out? Here there is the code for the basic idea, but the original one is a bit different:...

AngularJS watcher in constructor not fired while testing

angularjs,jasmine,angular-services,angularjs-watch
I created a factory which returns a constructor. The constructor includes a watcher looking at a property of the instance. When that property is changed in tests, the watcher is not fired. Outside of tests, it is fired. $rootScope.$apply doesn't seem to help. Here is a jsfiddle which contains a...

Is there a cost to repeating a $watch for the same variable?

angularjs,angularjs-watch
I have some textAngular code where I watch a variable in the scope, multiple times? Is there a simple way to only create this watch once, or can I detect that it exists??? The section of code is: taRegisterTool('fontColor', { display: "<button colorpicker type='button' class='btn btn-default ng-scope' title='Font Color' colorpicker-close-on-select...

spyOn listener watch function not working

javascript,angularjs,jasmine,karma-jasmine,angularjs-watch
When I try to spyOn the listener function of a $scope.$watch, is like never call the spyOn http://jsfiddle.net/b8LoLwLb/1/ My controller angular.module('angularApp') .controller('MainCtrl', function ($scope) { $scope.name = ''; this.changeName = function () { console.log('the name has change to ' + $scope.name); }; $scope.$watch('name', this.changeName); }); My test describe('Controller: MainCtrl', function...

Modifying a watched value within a $watch

javascript,angularjs,angularjs-watch
I have an <input ng-model='list' ng-list>, and I want to make sure that no duplicates appear in this text field—I want to automatically remove them if the list contains duplicates. I put a $scope.$watch('list', function(listValues) { in the controller, and try to remove any duplicates from listValues, but have problems....

How to use an isolated scope property properly?

angularjs,angularjs-directive,angularjs-watch,controlleras
How to use an isolated scope property properly? I have a directive, that is called from a page controller, with an attribute item passed to it, e.g. <my-directive item="myItem"></my-directive>, containing an id. The code below will not work, as it seems like $scope.item is undefined in the controller.. like I'm...

AngularJS - 2 selects for a range of years. Options in second one have to be greater or equal than first one selected

angularjs,angularjs-filter,angularjs-watch
I have 2 selects where I need to choose a range of years. The year of the second select has to be greater or equal than the first one. So if I select a year in the first select, the second select should change and show just the years greater...

ng-click value change + $scope.watch bind not working properly

javascript,angularjs,angularjs-scope,angularjs-ng-click,angularjs-watch
I have a scope variable '$scope.searchType' which is equal to 'createdAt' by default. In my HTML I have options that change the scope variable value: <ul class="dropdown-menu" role="menu"> <li><a ng-click="searchType = 'Anything'">Anything</a></li> <li><a ng-click="searchType = 'Payment'">Payment</a></li> <li><a ng-click="searchType = 'Total'">Total</a></li> <li><a ng-click="searchType = 'Tax'">Tax</a></li> <li><a...

How to update scope var from Math expression and another scope var?

angularjs,angularjs-scope,angularjs-watch
Not sure if I made myself clear on my question but what I really want is to update the min-width with ng-style for each <li> within an ng-repeat to equal the percentage of 100 / array.length. My first solution is simply: <li ng-style="{'min-width': (100 / array.length) + '%'}"> This works,...

Angularjs $watchCollection on $rootScope not triggered when values updated from directive

javascript,angularjs,events,angularjs-directive,angularjs-watch
I'm running into a bit of an issue solving a problem with some Angularjs functionality I'm working on. The basic idea is that I have a system where certain criteria must be met before the user is allowed to advance to the next section of the app. One example of...

angularJS why $scope.$watch cant't work?

javascript,angularjs,angularjs-scope,angularjs-watch
I want to add a $watch to watch $scope.data is changed or not, but it cant't work [http://jsbin.com/biqesojaqu/1/edit?html,js,console,output][1] app.html <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script> <meta charset="utf-8"> <title>JS Bin</title> </head> <body ng-app="App" ng-controller="TestController"> <div> <ul> <li ng-repeat="item in data"> {{ item.name }}--{{ item.status...