TypeError:self.parent.context.gotToManageCategoryPage不是函数

时间:2016-08-07 07:17:29

标签: angular ionic-framework firebase ionic2

我正在使用Firebase和Angular2。不知何故,它通过浏览器控制台显示此错误:

  

TypeError:self.parent.context.gotToManageCategoryPage不是函数

点击“管理类别”按钮时会出现错误。

这是我的代码:

export class HomePage {
    //Will be true if the user is Logged in.
    public isLoggedIn = false;
    //Will be true if the user is Admin.
    public isAdmin    = false;
    
    constructor(public nav: NavController, public menu: MenuController, public authData: AuthData) {
        this.nav = nav;
        this.menu = menu;
        this.authData = authData;
        
        firebase.auth().onAuthStateChanged((user) => {
            if(user) {
                this.isLoggedIn = true; //Set user loggedIn is true;
                var self = this;
                firebase.database().ref('/userProfile/' + user.uid).once('value').then(function(snapshot) {
                    let userInfo = snapshot.val();
                    if(userInfo.isAdmin == true) {
                        self.isAdmin = true;
                        console.log(userInfo);
                    }
                });
            } else {
                this.isLoggedIn = false; //Set user loggedIn is false;
            }
        });
    }
    
    //we are sending the admin to the ManageCategoryPage
    goToManageCategoryPage() {
        this.nav.push(ManageCategoryPage);
    }
    
    //we are sending the admin to the ManageProductsPage
    goToManageProductsPage() {
        this.nav.push(ManageProductsPage);
    }
}
<ion-list *ngIf="isAdmin==true">
  <button ion-item (click)="gotToManageCategoryPage()">
    <ion-icon name="grid" item-left></ion-icon>
    Manage Categories
  </button>
  <button ion-item (click)="gotToManageProductsPage()">
    <ion-icon name="heart" item-left></ion-icon>
    Manage Products
  </button>
</ion-list>

0 个答案:

没有答案