Ionic4: How to open external link from Side Menu

不羁的心 提交于 2020-04-30 19:35:58

问题


On my ionic project, I have created side menu at app.html to be available through the whole app, this menu contains items with links that should be opened externally. I have tried to open them with InAppBrowser but I have this error pups up:

uncaught (in promise) invalid views to insert

app.html:

<ion-list no-margin>
            <ion-item menuClose ion-item no-lines *ngFor="let l of SocialLinks" (click)="openPage(l.Url)">
                <ion-icon name="{{l.icon}}"></ion-icon>

           </ion-item>
</ion-list>

app.component.ts:

import { InAppBrowser } from '@ionic-native/in-app-browser';

...


@Component({
  templateUrl: 'app.html',
  providers: [InAppBrowser]
})

...

constructor(
...
 private iab: InAppBrowser
)    

...  

this.SocialLinks = [

     { title: 'twitter', Url: 'https://twitter.com', icon: 'logo-twitter' },
     { title: 'facebook', Url: 'https://facebook.com', icon: 'logo-facebook' },
     { title: 'instagram', Url: 'https://instagram.com', icon: 'logo-instagram' },
     { title: 'linkedin', Url: 'https://linkedin.com', icon: 'linkedin' },

];


...


OpenUrl(Url: string, myEvent) {
    const browser = this.iab.create(Url);
    browser.show();
  }

is there any way to open those links from the side menu?


回答1:


Have you noticed that the method you call in the click is not the same one you call when you show an Ionic Page



来源:https://stackoverflow.com/questions/52427032/ionic4-how-to-open-external-link-from-side-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!