我的Ionic 3 / Angular 2应用程序中出现一个奇怪的导航问题。我试图在2个组件(页面)之间进行通信,而父组件将子组件推到堆栈的顶部:
Maps
我实现了一个回调,以允许子级中的goToCheckIn(client, i) {
let that = this;
this.callback = function(params) {
return new Promise((res, rej) => {
that.handleApproval(params['index'], params['approval'], true)
res()
})
}
console.log(client)
this.navCtrl.push(CheckInApprovalPage, {
client: client,
index: i,
callback: this.callback
})
}
将参数传递给父级as seen in this post。完成工作后,子组件会弹出,并将数据传递给父组件:
nav.pop()
最后,回调使父级仅使用新的rateCheckIn(approval) {
let updated = Object.assign({}, this.client.check_in)
this.checkInService.update(updated).subscribe(
success => {
this.clientService.hideLoader()
this.callback({index: this.index, approval: approval}).then(() => this.navCtrl.pop({animate: false}))
}
)
}
对象来推送相同的子级视图。
client
此时,子视图将显示正确的handleApproval(index, approval, from_callback = false) {
let clients = _.slice(this.clients, index)
let unsolved = _.filter(clients, [ "check_in['approved']", null ])
let i = index + 1
if ( unsolved ) {
i = _.findIndex(this.clients, {id: unsolved[0]['id']})
}
if ( this.clients[ i ] ) {
this.navCtrl.push(CheckInApprovalPage, {
client: this.clients[ i ],
index: i,
callback: this.callback
})
}
}
数据约0.5秒,然后恢复为先前的client
数据。当我在子级中登录client
时(即使在几秒钟的超时后),它也会显示NEW this.client
,但视图仍显示先前的client
数据。任何想法为什么会发生这种情况?