2017-05-30 8 views
0

ionViewDidLeaveでどこが間違っているのか分かりません。私は "name ionViewDidLeaveを見つけることができません"と言う端末からエラーが出ます。それを使用するためにインポートする必要があるものはありますか?私は既にnavControllerをインポートしました。あなたはメソッド内で記述する場合はここでエラー:名前が見つかりませんionViewDidLeave

は私の

ts.file

import { Component } from '@angular/core'; 

import { NavController, ModalController } from 'ionic-angular'; 
import { EditPost } from '../edit-post/edit-post'; 

import { LoadingController } from 'ionic-angular'; 

@Component({ 
    selector: 'page-home', 
    templateUrl: 'home.html' 
}) 
export class Home { 

    buttonColor: string = '#787083'; 


    constructor (public navCtrl: NavController, public modalCtrl: ModalController, public loading: LoadingController) { 


//OTHER FUNCTIONS 

    /*Navigate to edit page */ 

    editPost(){ 
     this.buttonColor = '#553481'; //change button background color on click 
      this.navCtrl.push(EditPost, {}) 
      .catch(() => { 
       // Page requires authentication, re-direct to Login page 
       this.navCtrl.setRoot(Login, {routeToPage: 'EditPost'}); 

      }); 

      ionViewDidLeave(){ 

     this.buttonColor = '#787083'; 

      }; 

    }// end of editPost() 

}//close class 

HTML

<ion-footer class="footer"> 
    <ion-segment small class="footer"> 
        <ion-segment-button id="post" value="post" (click)="postEvent()" [ngStyle]="{'background-color': buttonColor}" small> <span class="footer">NEW POST</span></ion-segment-button> 
        <ion-segment-button id="edit" value="edit" (click)="editPost()" [ngStyle]="{'background-color': buttonColor}" small> <span class="footer">Edit Post</span></ion-segment-button > 
    </ion-segment> 
</ion-footer> 

答えて

1

ある

ionViewDidLeave() 

現在のスコープ(editPost)関数から関数を呼び出しています。オブジェクトから呼び出すための正しい方法は次のようになります。

this.ionViewDidLeave() 

が、私はそれが(ionViewDidLeaveは、イオンのページのライフサイクルの一部である)、それを呼び出すために右ではないと思う、と私は何がやりたいことは、この定義であることをあまりにも推測しますメソッドであり、コード内に型があります。正しいコードは次のとおりです。

export class Home { 

    buttonColor: string = '#787083'; 

    constructor (public navCtrl: NavController, public modalCtrl: ModalController, public loading: LoadingController) { 

    editPost(){ 
     this.buttonColor = '#553481'; //change button background color on click 
      this.navCtrl.push(EditPost, {}) 
      .catch(() => { 
       // Page requires authentication, re-direct to Login page 
       this.navCtrl.setRoot(Login, {routeToPage: 'EditPost'}); 
      }); 

    }// end of editPost() 


    ionViewDidLeave(){ 

     this.buttonColor = '#787083'; 

    }; 

}//close class 
関連する問題