【问题标题】:ERROR TypeError: Cannot read property 'loadVideoById' of null错误类型错误:无法读取 null 的属性“loadVideoById”
【发布时间】:2017-11-15 05:43:54
【问题描述】:

我无法在 ionic 2 中播放 youtube 视频。它显示此错误:

TypeError: 无法读取 null 的属性“loadVideoById”

launchPlayer(id): void {
    this.youtube.player.loadVideoById(id);
    this.youtube.videoId = id;
    return this.youtube;
  }

当我观察控制台时,我得到了 id 的值。

请帮忙。

【问题讨论】:

  • 可能this.youtube.player 为空
  • 是的,它显示 null 我如何解决它我是 ionic 2 的新手,请帮助
  • 显示整个控制器/组件/类的打字稿
  • playVideo(id){ this.player.launchPlayer(id) this.vPlayer = true; } //------------------------- --------- ---- ----------------- --------- // launchPlayer(id): void { console.log (this.youtube.player); this.youtube.player.loadVideoById(id); this.youtube.videoId = id;返回这个.youtube; }
  • 我从这个网站得到了教程piratesofjs.wordpress.com/2017/02/13/…

标签: angular typescript ionic-framework youtube ionic2


【解决方案1】:

我不知道问题是否解决了,但也许其他人需要答案:)

我遇到了这个问题,我在解决之前看到了你的问题


问题来自主页作为您的网站教程

 constructor(public navCtrl: NavController,public player: PlayerService,public youtubeService: YoutubeService,public loadingCtrl:LoadingController) {
    player.setupPlayer();
  }

从构造函数中移除player.setupPlayer();并插入这个

 ionViewDidLoad() {
    this.player.setupPlayer();
  }

希望对你有帮助

【讨论】:

  • 谢谢你的回答,我会试试这个,让你知道
猜你喜欢
  • 2021-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-05
  • 2017-12-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多