【发布时间】:2023-03-27 05:49:01
【问题描述】:
我制作了一个 heatMap Attribute 指令,它在调用时没有接收到值。
热图指令:
import {Directive, ElementRef, Input, Renderer, OnInit} from "@angular/core";
@Directive({
selector: '[HeatMap]',
})
export class HeatMapDirective{
@Input('startVal') public startVal: string;
constructor(private el: ElementRef, private renderer: Renderer) {
this.processHeatMap();
}
processHeatMap() {
console.log(this.startVal); // prints undefined.
}
}
HTML 元素:
<td class="pad-10" [startVal]="'25'" HeatMap> 25 </td>
我有一个场景,我需要同时传递字符串和数值,但两者都不起作用。我错过了什么吗?
【问题讨论】:
-
你有什么错误吗?
-
没有错误!
console.log(this.startVal); // prints undefined. -
检查 angular2 生命周期钩子。构造函数中没有初始化的@Input 值
标签: angular angular2-directives