简体   繁体   中英

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";
     }
}

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

使用返回“红色” <-引号

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM