I have a component that displays data, and if one wishes to edit/add data, they can do so under certain fields using a text box with a cancel/save button below.
Due to the fact that I am using a third party product in development, I do not have complete access to the code. In order to get the desired functionality, I need to change the behavior.
What I want is for the value in the displayed data table to reflect the changes made by the user. For example, if I change a default "name" value from, say, "default name" to "my name" in the given text box, when I hit save, and the text box disappears showing that data again, it should say "my name" not "default name". As of how it is now, it just says "default name" until the page is refreshed.
My idea was this: add my own function which makes its own patch request to the back end, replacing the third party product's own function that comes with the custom element. On success, my function does the following:
newData = "";
patchMyData(event: string, thirdPartyData: any) {
const dataObj = {
...
}
this.myService.patchData(dataObj)
.subscribe((res: any) => {
// sets data to user entered value on success
this.newData = event;
},
(error: any) => {
// Sets data to previous value on failure
this.newData = thirdPartyData.item.data;
})
}
In the template, I have the following:
<third-party-custom-element
...
(changeData)="patchMyData($event, thirdPartyData);thirdPartyData.item.data = newMemo;"
>
</third-party-custom-element>
thirdPartyData.item.data being the variable the third party product uses to display that particular value in the template.
Unfortunately what I think I'm finding is that the thirdPartyData.item.data = newMemo part on the template executes before patchMyData($event, thirdPartyData) can finish executing and set the newData variable, so the element will always show the previous value.
Is there a way to make sure the value is set after the function runs? Or another solution that might be better, taking into account that I cannot access the full code given the third party product involved?
Thanks!
newMemoas string, can you turn it into an observable? so you then you can useasyncin the template? (e.g patchMyData($event, thirdPartyData);thirdPartyData.item.data = newMemo | async;)