albert albert - 1 year ago 181
AngularJS Question

Angular.js: use color code in $watch

how can I use a color code in a String variable and link this variable to a $watch expression?

$scope.$watch($scope.backgroundTextColor, function(){
// code inside function

With the example code I get the next error:

"Error: [$parse:lexerr] Lexer Error: Unexpected next character at columns 0-0 [#] in expression [#9c5c5c]...

Answer Source

You are passing the Value of $scope.backgroundTextColor

You need to pass the name of the variable eg

$scope.$watch('backgroundTextColor', function(newValue, oldValue){
      // code inside function

Have a look at Responding to Scope Changes

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