该应用程序是一个简单的锻炼输入工具。它为CRUD操作执行基本API调用。 App Display
创建新条目并将其存储到数据库后,我无法重新加载“锻炼”选项卡。我能够操纵NavController为它设置root来显示更新的数据,但它只在Add Workout选项卡下。 Workouts updated in Add Workout tab当我选择回Workout选项卡时。它将结果显示为附加的第一张图像。
我认为这是因为构造函数和NgOnInit只初始化了一次。我怎么能绕过这个?
这是Workout选项卡的代码。
export class WorkoutPage {
navCtrl;
workoutService;
workouts;
static get parameters() {
return [NavController, WorkoutService];
}
constructor(navCtrl, workoutService) {
this.navCtrl = navCtrl;
this.workoutService = workoutService;
this.workoutService.getWorkouts().subscribe(workouts => {
this.workouts = workouts;
})
}
ngOnInit() {
this.workoutService.getWorkouts().subscribe(workouts => {
this.workouts = workouts;
})
}
workoutSelected(event, workout) {
this.navCtrl.push(WorkoutdetailPage, {
workout: workout
})
}
}
这是我在将新条目添加到数据库后执行setRoot的方法。
onSubmit() {
var workout = {
title: this.title,
note: this.note,
type: this.type
}
this.workoutService.addWorkout(workout)
.subscribe(data => {
this.result = data;
}, err => console.log(err),
() => console.log("Workout added"));
this.navCtrl.setRoot(WorkoutPage);
}
我真的需要一种方法来刷新Workout页面上的数据。非常感谢您的帮助。