I'm trying to pass a map from an angular html template to a custom directive.
I guess I succeed to pass it as an object, because I can console.log the map values. But when I try to set or get values from the map I get an error.
My code:
html template
<canvas id="seatsCanvasMain"
name="seatsCanvasMain"
appTheaterMap [takenSeatsMap]="show.theaterMap"
style="border:1px solid black">
</canvas>
Directive:
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
}
}
}
Anybody knows what can I do? I would also appreciate other methods on how to pass this map to the directive
Many thanks