簡體   English   中英

按值更改字體顏色

[英]Change font color by value

視頁面上的值來更改文本的顏色?

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

{{item.temp.day}}的數據(數值)應取決於文本的顏色。 其中“ ntvg”是數據(字符串值),應取決於文本的顏色。

如果大於0 item.temp.day-紅色字體顏色。 否則:藍色。

腳本:

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

似乎您正在通過使用[] (帶有指令的屬性綁定)將Angular 1和Angular 2整體混合在一起。

當您使用A1時, ng-style指令不應放在[]方括號內,並且您不應該在ng-style表達式內使用插值。

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

其他功能如下所示

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

分叉的Plunkr

使用返回“紅色” <-引號

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM