2017-09-27 62 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