You can pass the Event object to your method using the $event keyword
<div (click)="ToBank($event)"></div>
and then use it to set the div's id.
ToBank(event) {
event.target.id = 'nyDiv';
}
As far as I understand, you also want to pass the ids to the ToBank() method. You can do it by adding a second parameter
ToBank(event, id) {
event.target.id = id;
}
and then providing the ids in the second arguments.
<div (click)="ToBank($event, 'id1')"></div>
<div (click)="ToBank($event, 'id2')"></div>
<div (click)="ToBank($event, 'id3')"></div>
Using template variables, you can pass the DOM element without having to pass the entire Event object.
<div #divOne (click)="ToBank(divOne, 'id1')"></div>
<div #divTwo (click)="ToBank(divTwo, 'id2')"></div>
<div #divThree (click)="ToBank(divThree, 'id3')"></div>
ToBank(element, id) {
element.id = id;
}
Another approach is to store the current ids in a property
<div id="{{ ids[0] }}" (click)="ToBank(0, 'id1')"></div>
<div id="{{ ids[1] }}" (click)="ToBank(1, 'id2')"></div>
<div id="{{ ids[2] }}" (click)="ToBank(2, 'id3')"></div>
ids = ['', '', '']; // no ids at first
ToBank(arrayIndex, id) {
this.ids[arrayIndex] = id;
}
or make them depend on a certain property using the ternary operator.
<div id="{{ conditions[0] ? 'id1' : '' }}" (click)="ToBank(0)"></div>
<div id="{{ conditions[1] ? 'id2' : '' }}" (click)="ToBank(1)"></div>
<div id="{{ conditions[2] ? 'id3' : '' }}" (click)="ToBank(2)"></div>
conditions = [false, false, false]; // no ids at first
ToBank(arrayIndex) {
this.conditions[arrayIndex] = true;
}
Note that you normally do not need to use getElementById() and alike in Angular. Setting the id only really makes sense if you have some styles for it, but in that case, a class is probably better.