In crafting a versatile method, I have devised the following code snippet:
fetchArticle(loading: Loading): void {
this.articleService.getArticleById(this.data.definition.id)
.map((response: any) => response.json())
.subscribe((response: any) => {
if (response.definition.is_purchased) {
//additional instructions
} else {
//more instructions
}
loading.dismiss();
} else {
loading.dismiss();
}
}, () => {
loading.dismiss();
});
}
The method invoking this function looks like the following:
myCallerFunction() {
const loading = this.loader.create({
content: 'loading...'
});
loading.present();
this.fetchArticle(loading); //Can I place `loading.dismiss()` here?
}
To streamline the process, I am seeking advice on how to eliminate the loading parameter from the generic fetchArticle()
method and move it within the parent function (myCallerFunction()
) after resolving the subscription. Can you suggest a way to achieve this?