I have a tabs page which passes a model through rootParams. However, the first tab (or the one which is selected by default) always gets undefined params. Can you help me solve it? Here is the code.
tabs.ts:
private tab1: any;
private tab2: any;
private model: any;
constructor(public navCtrl: NavController,
public alertCtrl: AlertController,
private noteService: NoteService,
private userService: UserService,
private loadingCtrl: LoadingController,
private noteModel: NoteModel,
public params:NavParams) {
// set the tabs
this.tab1 = Tab1Page;
this.tab2 = Tab2Page;
this.getModel();
}
tabs.html:
<ion-content padding>
<ion-tabs tabsPlacement="top">
<ion-tab tabIcon="create" [root]="tab1" [rootParams]="{model: model}"></ion-tab>
<ion-tab tabIcon="eye" [root]="tab2" [rootParams]="{model: model}"></ion-tab>
</ion-tabs>
</ion-content>
tab1.ts
export class Tab1Page{
model: any;
constructor(navParams: NavParams) {
this.model = navParams.get("model");
}
}
model.ts
@Injectable()
export class NoteModel {
id:any;
// dates
name: string;
year: string;
constructor() {
}
getNote(data) {
this.name = data.name || '';
this.year = data.year || 2000;
return this;
}
}