我正在尝试将地图从角度 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
}
}
}
有人知道我能做什么吗?我也很欣赏有关如何将此映射传递给指令的其他方法
非常感谢