Hi Friends i want to navigate to home page inside this provider. How can i achieve this ?
below is the code i am using.
import { NavController, LoadingController} from ‘ionic-angular’;
@Injectable()
export class DataFactory {
url: any;
token: any;
constructor(
public _navCtrl: NavController,
private _http: Http
) {
this._navCtrl.push(HomePage);
}
this is showing an error “no provider for NavController”.
The way I ended up doing this, after being advised to do so, was setting up an observable in the provider and have the app component subscribe to it, waiting for the redirects.
Thanks for Replying. can you please share the code
Something along the lines of this
import { Observable } from 'rxjs/Observable';
@Injectable()
export class DataFactory {
private observable;
private observer;
url: any;
token: any;
constructor(
public _navCtrl: NavController,
private _http: Http
) {
this.observer.next({navigateTo: "HomePage"});
}
navigation(): Observable<any> {
if(!this.observable) {
this.observable = new Observable(observer => {
this.observer = observer;
});
}
return this.observable;
}
}
And in your app component
private components = {
"HomePage": HomePageComponent
};
constructor() {
this.dataFactory.navigation().subscribe(
data => {
this.navCtrl.push(this.components[data.navigateTo]);
}
);
}