Karan
Karan

Reputation: 1108

Watch is not executing when updating inner objects in array

I am creating a project using angularJS. I have a problem while using watch in my project. I am updating the inner objects of the array.

 $scope.$watch('demoData',function(_n, _o) {
      console.log("watchExecuting")
      },true); 

Here is the Jsfiddle: http://jsfiddle.net/HB7LU/29132/

Upvotes: 1

Views: 39

Answers (1)

Sa E Chowdary
Sa E Chowdary

Reputation: 2075

You need to watch over the input with ng-model value like below

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
 
	$scope.demoData = []
  $scope.lid = "f0b751df4f0444d8";
  $scope.demoData[$scope.lid] = {"textBox":"test"}
 	console.log( $scope.demoData)
  $scope.demo = function(){
   //console.log( $scope.demoData)
  }
  $scope.$watch('demoData[lid].textBox',function(_n, _o) {
  console.log("watchExecuting")
  },true);
});
<!DOCTYPE html>
<html ng-app="plunker">

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <script data-require="[email protected]" src="https://code.angularjs.org/1.4.12/angular.js" data-semver="1.4.9"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
 <input type = "text" ng-model="demoData[lid].textBox" ng-change="demo()">
  </body>

</html>

Upvotes: 2

Related Questions