1

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/

1
  • 1
    Any specific reason for $scope.demoData = [] for defining it as array because if its defined as object it works $scope.demoData = {} jsfiddle.net/HB7LU/29134 Commented Apr 18, 2017 at 11:44

1 Answer 1

2

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>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.