Data bindings don't get updated if their values are changed after an await
statement.
handle() {
this.message = 'Works'
}
async handle() {
this.message = 'Works'
}
async handle() {
await new Promise((resolve, reject) => {
resolve()
})
this.message = 'Works'
}
async handle() {
await new Promise((resolve, reject) => {
setTimeout(() => resolve(), 3000)
})
this.message = 'Doesn\'t work'
}
handle() {
new Promise((resolve, reject) => {
setTimeout(() => resolve(), 3000)
})
.then(() => this.message = 'Works')
}
Why do the last two not behave the same? aren't they supposed to be the same thing?
Ionic: 3.9.2
Angular: 5.0.3
TypeScript: 2.4.2
EDIT: I came across another problem with this which may be useful to some.
Changing the values of a binding in the constructor behaves differently to ionViewDidLoad or ngOnInit!
constructor(private zone: NgZone) {
// This will cause the same problems, bindings not updating
this.handle()
}
constructor(private zone: NgZone) {
// Unless you do this...
this.zone.run(() => {
this.handle()
})
}
ionViewDidLoad() {
// But I think this is better/cleaner
this.handle()
}