albert albert - 6 months ago 84
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]...


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