vineet
vineet

Reputation: 14236

How to implement angular $watch function in core javascript

As i know that angular watches are evaluated in every digest loop. So, i need such kind of function in core javascript for watch http response json object.

Somethings like this:-

var oldResponseData='{"name":"Ram","age":"45"}';
function myCustomeWatch(httpResponseData){
  if(httpResponseData===oldResponseData){
     return false;
  }else{
     oldResponseData=httpResponseData;
  }
}
.
.
.
 httpResponseData='{"name":"Ram","age":"46"}';//'{"name":"Ram","age":"45"}' != '{"name":"Ram","age":"46"}'
setInterval(function(){
   myCustomeWatch(httpResponseData);
},3000);

Upvotes: 3

Views: 100

Answers (1)

Narendra CM
Narendra CM

Reputation: 1426

You can also use Object.watch. More info is available here

And here is the polyfill for ES5 compatible browsers

Upvotes: 1

Related Questions