Reputation: 19
Hello I'm working on ionic 3
and I have data stored in local storage. I would like to use these data in a component , but ionViewDidLoad
(which is work perfectly in a normal page) doesn't work on a component and I have got the below error:
So please is there any other suggestions ?
component code (offre.ts):
import { Component, Input , Output } from '@angular/core';
import { AngularFireDatabase, FirebaseListObservable } from "angularfire2/database";
import { IonicPage, NavController, NavParams} from 'ionic-angular';
import { NativeStorage } from '@ionic-native/native-storage';
@Component({
selector: 'offre',
templateUrl: 'offre.html',
})
export class OffreComponent {
@Input('var') var;
text: string;
datas: FirebaseListObservable<any>;
user : any ;
constructor(public navCtrl: NavController, public db: AngularFireDatabase, public nativeStorage: NativeStorage) {
this.datas=db.list('/posts');
}
ngAfterViewInit(){
console.log(this.var);
}
}
Upvotes: 0
Views: 1567
Reputation: 71
use ionViewCanEnter() which will be called before the ionViewDidLoad()
Upvotes: 1
Reputation: 65978
I have tried it with my app and it doesn't give any run time error.But when you use the Angular components always try to use the Angular life cycle hooks.On your use case where you can use ngAfterViewInit()
hook.
Respond after Angular initializes the component's views and child views. Called once after the first ngAfterContentChecked(). A component-only hook.
Upvotes: 0