简体   繁体   中英

Angular 2 ngStyle cannot bind font-family start with a number

I have tried to bind dynamic font-family to text. But I face a problem that a font name start with a number cannot be bind to DOM element. I've done a lot of research but I cannot find why it happens.

Template:

<h2 [style.font-family]="font">Hello {{name}}</h2>

Component class:

constructor() {
    this.name = `Angular! v${VERSION.full}`;
    this.font = '28 Days Later';
}

With font "Arial", DOM generate fine: 在此处输入图片说明

But, it seems to ignore generating font "28 Days Later" 在此处输入图片说明

Here is Plunker

I appreciate any suggestion, thanks in advance!

这很简单,只需像这样使用您的字体:

 this.font = "'28 Days Later'";

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