Ionic 2 on function does not refresh the ngModel p

2019-09-16 05:31发布

问题:

I use wavesurfer.js and after it's finish playing i want to change the pause button back to play button, but until i open a toggle or do something nothing happen.

this.wavesurfer.on('finish', function () {
  this.isPlaying = false;
}.bind(this));

I have this simple code, i used console.log() so i know it has been called properly, and the binding is also good. However i see the changes only after i do something on the page.

What should i do? Any help would be appreciated.

回答1:

after it's finish playing i want to change the pause button back to play button, but until i open a toggle or do something nothing happen

I believe you are using this.playing in your html..

Your wavesurfer.js is changing the value outside Angular's zone.

Try using ngZone API:

import {NgZone} from '@angular/core';

constructor(private ngZone:NgZone){}

//...
this.wavesurfer.on('finish', function () {
  this.ngZone.run(()=>{
     this.isPlaying = false;
  });
}.bind(this));

NgZone API