I am working with a li
tag that has a *ngFor
directive:
<li *ngFor="let items of buttons">
<button (click)="newMap(items.id, $event)">
{{ items.name }}
</button>
</li>
The buttons array looks like this:
buttons = [
{name: 'Berlin', id: 'mapBerlin'},
{name: 'New York', id: 'mapNewYork'},
{name: 'Tokyo', id: 'mapTokyo'}
]
I am assigning a (click)
method to the button
tag:
(click)="newMap(items.id, $event)"
In TypeScript:
newMap($event) {
console.log($event)
}
When I click on button number 1, I see this message in the console:
- mapBerlin
For button number 2:
- mapNewYork
and so on.
Is there a way to create a function like this one?:
newMap(this.id) {
this.markers = this.id
}
I would like to change this.markers
to this.id
(e.g., this.mapBerlin
, this.mapNewYork
, etc.)