我正在尝试将一个映射从一个angular html模板传递到一个自定义指令。
我想我成功地将其作为对象传递,因为我可以console.log映射值。但是,当我尝试从映射中设置或获取值时,我得到一个错误。
我的代码:
html模板
<canvas id="seatsCanvasMain"
name="seatsCanvasMain"
appTheaterMap [takenSeatsMap]="show.theaterMap"
style="border:1px solid black">
</canvas>指令:
import { Directive, ElementRef, Input } from '@angular/core';
@Directive({
selector: '[appTheaterMap]'
})
export class TheaterMapDirective {
canvas;
@Input() takenSeatsMap: any;
constructor(private el: ElementRef) {
this.canvas = this.el.nativeElement;
}
ngOnInit() {
this.canvas.onclick = (e) => {
console.log(this.takenSeatsMap);//this will console log the map as an object. at first it seems that it passed correctly
this.takenSeatsMap.get('4-4'); // ERROR TypeError: _this.takenSeatsMap.get is not a function
}
}
}这是console.log

有人知道我能做什么吗?我还希望使用其他方法来将这个map传递给指令
非常感谢
https://stackoverflow.com/questions/51382292
复制相似问题