Is it possible to trigger a function that has a parameter in it like trigger(id) in ngOnInit?
I have a function that I want to trigger on (click) event as well as in ngOnInit so when the page first load it triggers basically the same function because it calls to the same API end-point.
function to be triggered in ngOnInit
getOrdersFromOrigin(id: number): void {
...
}
so in ngOnInit would be something like this maybe? its showing an error "Cannot find name 'id'"
ngOnInit() {
this.getOrdersFromOrigin(id);
}
Id is coming from my ngFor, its an Id of an item which I want to click (click)="getOrdersFromOrigin(id)"
idis part of the scope ofgetOrdersFromOrigin()so it would not be declared in the scope ofngInInit(). Unless you know which id to call you can't do it, id need to be set or a value need to be used instead.ngForand just passing theitem.idin my function in(click)event.