2017-08-09 32 views
0

你好我正在ionic 3工作,我有數據存儲在本地存儲。我想在一個組件中使用這些數據,但ionViewDidLoad(在普通頁面完全正常工作)沒有一個組件上工作,我有以下錯誤:如何在組件中使用ionViewDidLoad()?

this error

所以請爲還有其他建議嗎?
組件代碼(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); 
    } 
} 
+0

你能告訴你的組件的代碼? – Sampath

+0

@桑帕斯完成! ngOnInit有用嗎? –

+0

你可以在控制檯窗口上共享錯誤的完整堆棧跟蹤嗎? – Sampath

回答

0

我與我的應用程序試了一下,並沒有給出任何運行時error.But當您使用的角度分量總是嘗試使用角度生命週期在您的使用案例中,您可以使用ngAfterViewInit()掛鉤。

Offical Doc

Respond after Angular initializes the component's views and child views. Called once after the first ngAfterContentChecked(). A component-only hook.

1

使用ionViewCanEnter(),這將在ionViewDidLoad()之前被調用

相關問題