'Call a method from inside of subscribe
Im trying to call a method from inside of subscribe in angular/ionic. But its not working. Here is my code:
somemethod()
{
const browser = this.iab.create('https://someurl.com');
browser.on('loadstart').subscribe(event=>{
if(event.url === 'https://specificurl.com'){
browser.close();
// trying to call a member method from here , working
this.mymethod();
}
});
browser.on('exit').subscribe(eventx=>{
// trying to call a member method from here
this.mymethod();
});
}
mymethod()
{
http.get<any>(url).subscribe(e=> {
this.myvar = e.response; // this data is shown to user, but the user interface is not changing until something is clicked by the user
});
}
Solution 1:[1]
Just in case... You create the in app browser for url https://someurl.com but you subscribe and check for https://specificurl.com. What if you change it to listen for what you create?
if(event.url == 'https://someurl.com'){
console.log(event)
browser.close();
}
If the block itself is reachable go over the scope. Example:
@Component({
templateUrl: 'app.html',
})
export class MyApp {
rootPage: any = TabsPage;
response$: Observable<any>;
constructor(platform: Platform) {
platform.ready().then(() => {
this.myMethod();
});
}
myMethod() {
console.log('cool');
// TODO supply valid url and other params if neccessary
this.response$ = http.get<any>(url).pipe(data => {return data;})
}
}
Then use response$ like so:
<div>{{ response$ | async}}</div>
https://stackblitz.com/edit/ionic-p5qfps?file=app%2Fapp.component.ts
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
