尝试将十六进制中的颜色值传递给指令,但无法理解为什么它不会识别它
在html中
<button md-button
highlight
[defBackColor]="#FFFFF7" [defColor]="#3498db
[background]="#2980b9" [foreground]="#FFFFF7"> {{filterType}}</button>
指令
import {Directive, HostBinding, HostListener, Input} from '@angular/core';
@Directive({
selector: '[highlight]'
})
export class HighlightDirective {
@Input() defBackColor: string = 'transparent';
@Input() defColor: string = 'black';
@Input('background') highlightBackColor: string = 'blue';
@Input('foreground') higlightColor: string = 'white';
@HostBinding('style.backgroundColor') backgroundColor: string = this.highlightBackColor;
@HostBinding('style.color') textColor: string = this.higlightColor;
constructor() { }
}
具有以下相同上下文的各种错误消息: 未处理的Promise拒绝:模板解析错误:
分析程序错误:[#FFFF7]中第1列的意外标记# ng:///AppModule/AppComponent.html@29:18(“index”&gt; ] [defBackColor] =“#FFFFF7”[defColor] =“#3498db”[背景] =“#2980b9”[前景] =“#FFFFF7”
答案 0 :(得分:1)
使用字符串[defBackColor] =&#34;&#39;#FFFFF7&#39;&#34;