2017-09-27 59 views
1

結合我有這樣低於組件:如何CSS樣式從打字稿方法與角度

@Component({ 
    selector: 'app-car-item', 
    templateUrl: './car-item.component.html', 
    styleUrls: ['./car-item.component.css'], 
}) 
export class CarItemComponent { 
    public style: string 

    addStyle() { 
    this.style = 'font-size: 20px' 
    } 

我如何能實現addStyle()方法來改變字體大小在汽車item.component.css?

回答

0

我不知道,如果你可以改變CSS文件,但你可以只使用:

addStyle() { 
    document.getElementById(id).style.fontSize = "20px"; 
    } 
1

這是不是你的角度做到這一點!這是你會怎麼做:

在你CarItemComponent添加vairable的字體大小,例如:這個數字

fontSize: number; 

在你addStyle()設置爲你希望使用的字體大小和你的模板添加到您要更改的字體大小的元素:

[style.font-size.px]="{{ fontSize }}" 
+0

對不起,我是Angular的新手。我在哪裏必須添加這一行:[style.font-size.px] =「{{fontSize}}」? – Luki

+0

在你想要改變字體大小的模板上:

content
newnoise