如何将十六进制数传递给指令输入?
How to pass hex number to directive input?
尝试将十六进制颜色值传递给指令,但无法理解为什么无法识别它
在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() { }
}
上下文相同的各种错误消息如下:
未处理的承诺拒绝:模板解析错误:
Parser Error: Unexpected token # at column 1 in [#FFFFF7] in
ng:///AppModule/AppComponent.html@29:18 ("index" >
][defBackColor]="#FFFFF7" [defColor]="#3498db" [background]="#2980b9" [foreground]="#FFFFF7"
使用字符串 [defBackColor]="'#FFFFF7'"
尝试将十六进制颜色值传递给指令,但无法理解为什么无法识别它
在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() { }
}
上下文相同的各种错误消息如下: 未处理的承诺拒绝:模板解析错误:
Parser Error: Unexpected token # at column 1 in [#FFFFF7] in ng:///AppModule/AppComponent.html@29:18 ("index" > ][defBackColor]="#FFFFF7" [defColor]="#3498db" [background]="#2980b9" [foreground]="#FFFFF7"
使用字符串 [defBackColor]="'#FFFFF7'"