Arif Arif -3 years ago 121
Javascript Question

AngularJS model object value can't change using dynamic key

app.controller('indexController', ['$scope', '$location', 'authService', function ($scope, $location, authService) {

var vm = this;
vm.$onInit = function () { = {
"home": true,
"welcome": false,
"user": false,
"logout": false,
"login": false,

$scope.$watch('', function (newObj, oldObj) {
Object.keys(newObj).filter(function (key) {[key] = newObj[key] !== oldObj[key];
}, true);


Here i try to change
object property but it shows below error :

angular.js:14642 Error:
at angular.js:88
at m.$digest (angular.js:18248)
at b.$apply (angular.js:18480)
at HTMLAnchorElement. (angular.js:27290)
at HTMLAnchorElement.dispatch (jquery-3.1.1.js:5201)
at HTMLAnchorElement.elemData.handle (jquery-3.1.1.js:5009)

Answer Source

It shows the error because your code is causing an infinite $digest loop because you are trying to change the model during the digest loop.

To solve the problem avoid changing the model using $watch.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download