I need to delay call of function for few seconds. I have solution which work but enough good.
public recieveNewContact() {
this.allData();
setTimeout(() => {
this.lastAddedItem()
}, 100)
}
public ngOnInit() {
this.allData()
}
allData() {
this.accountsService.getContactPerson().subscribe(
(data) => {
console.log(data)
}
)
}
This is work good but i don't like this... I need better solution maybe with rxjs ? Delay ?
which is very important.
In this case, I don't need this:
allData() {
this.accountsService.getContactPerson().subscribe(
(data) => {
console.log(data)
this.lastAddedItem()
}
)
}
Because i wan't to load lastAddedItem() on init.... Only when is recieveNewContact triggered.
I will try to explain once again:
public recieveNewContact() {
this.allData();
this.lastAddedItem()// here to be called when is allData finished without setTimeout
}
receiveNewContact? something likecallLastAddedwhich you set tofalseon yourngOnInitfunction and totrueon yourrecieveNewContactfunction. So you would just need to check the flag in yoursubscribecallbackngOnInityou are callingallData()and getting all contact persons. So when exactly are you callingrecieveNewContact()and what islastAddedItem()function? Is it an API call?