watching variables in a service

9 views
Skip to first unread message

Garey Mills

unread,
May 20, 2020, 1:02:15 PM5/20/20
to Angular and AngularJS discussion
I have a service that returns an object that has a single variable, say w, with some numeric value. I want to 
build a directive that publishes that value in an HTML page. Using a link function in the directive, I tried this:

 $watch(variableService.w, numToPublish,
   function(variableService.w, numToPublish) {
       numToPublish = variableService.w;
       element.appendChild(numToPublish);
   });

but I get: Uncaught SyntaxError: Unexpected token '.'

I've also tried square brackets, as in variableService['w']. Chrome developerTools console that the square bracket is the unexpected token.

Is there some recipe that will allow me to watch variables on a service?

Thanks

Reply all
Reply to author
Forward
0 new messages