更新时间:2023-02-12 07:58:08
看起来playing
未以角度捕获为更改检测器机制的一部分。
第一个是为
playing
变量使用setter和getter
函数始终作为更改检测器的一部分发挥重要作用,因此它可确保您在变量中所做的更改得到反映。
*.ts中的get playingValue(){
return this.playing;
}
set playingValue(playing){
this.playing = playing;
}
*.html中的
Playing is {{ playingValue }}
第二个选项是使用setTimeout(.)
this.service.downloadAudio(this.gender, this.style, this.ageRange, media).subscribe(abuf => {
this.context.decodeAudioData(abuf, buffer => {
this.source.buffer = buffer;
setTimeout(()=>this.playing = true); //setTimeout
console.info(`Playing is ${this.playing}`);
this.source.start(0);
}, y => {
console.info('Error: ' + y);
});
this.loading = false;
}, () => {
this.loading = false;
});