selectedIndex属性绑定到index属性。当在 AngularFireAuth 可观察对象中更改索引属性时,视图不会更新,如下所示。为什么不?它在可观察对象之外的任何地方都可以正常工作。.ts 和 .html 文件如下所示。
这是html文件
<ion-tabs [selectedIndex]="index">
<ion-tab [root]="t0" tabTitle =" My Account" tabIcon="body"></ion-tab>
<ion-tab [root]="t1" tabTitle ="Sections" tabIcon="home"></ion-tab>
</ion-tabs>
这是 .ts 文件
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase'
@IonicPage()
@Component({
selector: 'page-tabs',
templateUrl: 'tabs.html',
})
export class TabsPage {
index = 0;
t0 = "AccountPage";
t1 = "HomePage";
constructor(public navCtrl: NavController, public navParams: NavParams, public afAuth: AngularFireAuth) {
afAuth.authState.subscribe((fbuser: firebase.User) => {
if (!fbuser) {
this.index = 0;
console.log(this.index)
}
else {
this.index = 1;
console.log(this.index)
}
});
// setting the index outside the observable works normally
}
ionViewDidLoad() {
}
}