【问题标题】:Ionic 2 / refresh iFrame in TabsIonic 2 / 在选项卡中刷新 iFrame
【发布时间】:2018-06-02 18:41:18
【问题描述】:

在我的 ionic 2 应用程序中,我有 3 个选项卡。其中一个选项卡有一个集成的 iFrame。我知道这不是最好的方法,但目前我没有其他选择。 每次如果我回到带有 iFrame 的选项卡,我都需要刷新它。我该怎么做。

目前我在 tabs.html 中设置:

<ion-tabs (ionChange)="tabChange()">

并且 tabs.ts 中的 Funktion tabChange() 发布一个事件:

this.events.publish('tabChange', this.change)

在带有 iframe 的页面中,我必须订阅此事件:

constructor(public navCtrl: NavController, public events: Events) {

this.events.subscribe('tabChange', (n) => {

  // refresh iFrame here

  })
}

感谢您的帮助。

【问题讨论】:

  • Ionic 标签是否有路由版本?我的意思是,例如 Angular Material :您可以使用显示组件的选项卡,也可以使用路由插座显示路由的选项卡。你有路由器插座版本的标签吗?
  • 不,我没有。不明白你的意思,对不起
  • 我添加了@ViewChild('myiframe') myiframe,现在我可以访问 iframe。但是 this.myiframe.refresh() 以错误结尾

标签: angular ionic2


【解决方案1】:

好的,我找到了解决方案。 event.subscribe 必须在 ionViewDidEnter 内部而不是构造函数,因此每次我进入包含 iframe 的页面时都会调用它。

ionViewDidEnter(){

    this.events.subscribe('tabChange', (n) => {

      let src: string = this.myiframe.nativeElement.src;
      this.myiframe.nativeElement.src = src;

      this.events.unsubscribe('tabChange')

    })

}

【讨论】:

    猜你喜欢
    • 2017-09-12
    • 2018-02-04
    • 1970-01-01
    • 1970-01-01
    • 2016-05-11
    • 2013-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多