I have an angular Application with multiple Buttons which have specific IDs. each of them has a click function and I want to track if a user clicked the Button without changing anything in each of the Methods.
example code:
import { Component, ViewChild, ElementRef } from '@angular/core';
import { Observable } from 'rxjs';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
@ViewChild('BUTTON_EDIT', {read: ElementRef}) BUTTON_EDIT;
@ViewChild('BUTTON_ADD', {read: ElementRef}) BUTTON_ADD;
ele: Element;
ngAfterViewInit(): void {
let clickStream;
//check which element was pressed and get the id
//how can i check it?
clickStream = fromEvent(this.ele, 'clicked');
var id = this.ele.id;
clickStream.subscribe(event => {
//send info
});
}
}
click
:fromEvent(this.ele, 'click')
– Michael D