我正在为当前项目使用newsapi。使用html页面本身很容易打开“ data.url”。
[href]='data.url'
我的挑战是尝试使用一个函数打开url,因为仅粘贴'data'url'作为要由InAppBrowser插件打开的链接会导致我进入'localhost:8010 / data.url'。这是我以前的代码。
<ion-item *ngFor="let data of fetchedData?.articles; index as i" [href]="data.url" target="_blank" >
这是我的新代码。 HTML
<ion-item *ngFor="let data of fetchedData?.articles; index as i" (click)="openPage()" >
。ts
openPage() {
this.fetchedData = data
this.iab.create('data.url', '_blank');
}
我现在已经知道答案是这个
<ion-item *ngFor="let data of fetchedData?.articles; index as i" (click)="openPage(data.url)" >
代替此
<ion-item *ngFor="let data of fetchedData?.articles; index as i" (click)="openPage()">
然后在.ts文件中,我打算写...
openPage(url) { // here data.url is assigned to 'url'
this.iab.create(url, '_blank'); //'url' is called here to be opened in-app
}
javascript
我希望这可以帮助遇到相同问题的人