Dmitry Dmitry - 9 days ago 6
CSS Question

Change font color by value

As depending on the value on the page to change the color of the text?

<div [ng-Style]="color":colorFont({{item.temp.day}})> {{item.temp.day}} {{vm.symbal}}</div><br>


Where {{item.temp.day}} is data (numerical value) of which should depend on the color of text. Where "ntvg" is data (string values) which should depend on the color of the text.
If greater than 0 item.temp.day -Red font color. Else:blue.

script:

$scope.colorFont=function(var templiche){
if (parseFloat(templiche)>0) return color="red";
else {
return color="blue";
}
}

Answer

It seems like you are mixing Angular 1 & Angular 2 whole together by using [](property binding with directive).

As you are using A1 ng-style directive should be without placed [] square brackets & you shouldn't be using interpolation inside ng-style expression.

ng-style="{'color': colorFont(item.temp.day)}"

Additionally function would look like below

$scope.colorFont=function(templiche){
     if (templiche>0) return 'red';
      else {
        return 'blue';
      }
}

Forked Plunkr