I am trying to set values in a Map in angular. An I try to set the values when I click some particular buttons and invoke the onClick function
typeArray: Map<number,string>;
Rent(movieId: number){
this.typeArray.set(movieId,"Rental");
console.log(this.typeArray.get(movieId));
}
Purchase(movieId: number){
this.typeArray.set(movieId,"Purchased");
console.log(this.typeArray.get(movieId));
}
But I am getting this error
core.js:4197 ERROR TypeError: Cannot read property 'set' of undefined
at CartComponent.Purchase (cart.component.ts:77)
at CartComponent_tr_23_Template_button_click_13_listener (cart.component.html:34)
at executeListenerWithErrorHandling (core.js:14310)
at wrapListenerIn_markDirtyAndPreventDefault (core.js:14345)
at HTMLButtonElement.<anonymous> (platform-browser.js:582)
at ZoneDelegate.invokeTask (zone-evergreen.js:399)
at Object.onInvokeTask (core.js:27418)
at ZoneDelegate.invokeTask (zone-evergreen.js:398)
at Zone.runTask (zone-evergreen.js:167)
at ZoneTask.invokeTask [as invoke] (zone-evergreen.js:480)