Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当管线在角度方向发生变化时,外部js库不工作_Javascript_Angular_Angular Ui Router_Video.js - Fatal编程技术网

Javascript 当管线在角度方向发生变化时,外部js库不工作

Javascript 当管线在角度方向发生变化时,外部js库不工作,javascript,angular,angular-ui-router,video.js,Javascript,Angular,Angular Ui Router,Video.js,我在我的应用程序上使用一个外部库,我注意到当我更改路径然后返回库时,库停止工作。 库的导入方式如下所示: import videojs from "video.js" import "videojs-markers" .... ngOnInit() { this.video = videojs('demo'); this.video.on('pause', function () { this.onPauseVideo(this

我在我的应用程序上使用一个外部库,我注意到当我更改路径然后返回库时,库停止工作。 库的导入方式如下所示:

   import videojs from "video.js"
   import  "videojs-markers"
    ....
   ngOnInit() {
      this.video = videojs('demo');
      this.video.on('pause', function () {
        this.onPauseVideo(this.video.currentTime())
      }.bind(this));
      this.video.on('play', function () {
        this.onPlayVideo(this.video.currentTime())
      }.bind(this));

      this.setUpMarkers(this.video);
        this.subscription = this.commentService.commentsChange.subscribe((newComments:VideoComment[])=>{
          this.video.markers.add(newComments.map(el=>{
            return {time:el.time,text:el.text,overlayText:el.overlayText}})
          );

        })
      }


     ....

任何建议

  • 从代码中删除.bind(此)。箭头功能应该有帮助 你
  • 此行移动到构造函数(){} this.video=videojs(“演示”)

  • 删除所有事件监听器,如Ngondestory(){this.video.off('pause'))

  • 通常在外部工作时,您需要小心地重置
    ngondestory
    angular回调上的lib,以确保下一个
    ngOnInit
    正常工作。如何才能做到这一点?