我正在尝试构建一个列表视图,显示带有网站名称和网址的JSON数据。一切都很好。但是当我把onclick转到inAppBrowser时它会给我一个错误
下面的地址栏
http://localhost:8104/www.myjsonstringurl.com
在显示的窗口中
无法获取/网址
以下是我的resources.html页面的代码
<ion-header>
<ion-navbar>
<ion-title>Resources & Information</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<ion-item><p text-wrap>Our Resources page will take you to Mobile Devices default browser.</p></ion-item>
<!--
<ion-item><p text-wrap>Our Resources page will offer adding new resources and finding a team your area.</p></ion-item>
<ion-buttons>
<button ion-button full large color="secondary" style="color: #000000;">Add a resource!</button>
<button ion-button full large color="secondary" style="color: #000000;">Find a team in your area!</button>
</ion-buttons> -->
<ion-list>
<button ion-item detail-none *ngFor="let item of filteredList" (click)="openWithSystemBrowser(item.post.URL)">
<h4 text-wrap>{{item.post.Name}}</h4>
<p>{{item.post.URL}}</p>
</button>
</ion-list>
</ion-content>
我的代码
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { DataProvider } from '../../providers/data/data';
import { InAppBrowser, InAppBrowserOptions } from "@ionic-native/in-app-browser";
@IonicPage()
@Component({
selector: 'page-resources',
templateUrl: 'resources.html',
})
export class ResourcesPage {
url: any[];
tournments: any[];
filteredList = [];
listType = 'all';
options : InAppBrowserOptions = {
location : 'yes',//Or 'no'
hidden : 'no', //Or 'yes'
clearcache : 'yes',
clearsessioncache : 'yes',
zoom : 'yes',//Android only ,shows browser zoom controls
hardwareback : 'yes',
mediaPlaybackRequiresUserAction : 'no',
shouldPauseOnSuspend : 'no', //Android only
closebuttoncaption : 'Close', //iOS only
disallowoverscroll : 'no', //iOS only
toolbar : 'yes', //iOS only
enableViewportScale : 'no', //iOS only
allowInlineMediaPlayback : 'no',//iOS only
presentationstyle : 'pagesheet',//iOS only
fullscreen : 'yes',//Windows only
};
constructor(
private navCtrl: NavController,
private dataProvider: DataProvider, private inAppBrowser: InAppBrowser, private theInAppBrowser: InAppBrowser) {
this.dataProvider.getResource().subscribe((data: any) => {
this.tournments = data.posts;
this.filteredList = this.tournments;
});
}
public openWithSystemBrowser(tournament: string){
let target = "_system";
this.theInAppBrowser.create(tournament,target,this.options);
}
public openWithInAppBrowser(url : string){
let target = "_blank";
this.theInAppBrowser.create(url,target,this.options);
}
public openWithCordovaBrowser(url : string){
let target = "_self";
this.theInAppBrowser.create(url,target,this.options);
}
openWebpage(url: string) {
const options: InAppBrowserOptions = {
zoom: 'yes',
toolbar: 'yes',
enableViewportScale: 'yes',
}
// Opening a URL and returning an InAppBrowserObject
const browser = this.inAppBrowser.create(url, '_system', options);
console.log(url);
console.log(browser);
console.log("link viewed");
// Inject scripts, css and more with browser.X
}
/**
* open Resoures detail page
*
* @param tournament
*/
openResourcePage(tournament: any) {
this.navCtrl.push('ResourceDetailPage', {tournament: tournament});
}
/**
* search by text
*/
onSearch(event: any) {
const searchText = event.target.value.toLowerCase();
this.filteredList = this.tournments.filter(item => {
if ((item.post.NAME as string).toLowerCase().indexOf(searchText) > -1) {
return true;
}
return false;
});
}
segmentChanged(event: any) {
this.dataProvider.getResource(event.value).subscribe((data: any) => {
this.tournments = data.posts;
this.filteredList = this.tournments;
});
}
}
当我输入twitter.com这样的网址时,它运行正常。 json字符串具有完整地址http://url
有人可以帮忙。它不适用于浏览器,IOS或Android模拟器
答案 0 :(得分:0)
对于您传递给NSTextField
方法的选项,NSTextView
中context
的一个可能性this
不正确。
尝试在您的班级上下文中将您的选项定义为this.options
或inAppBrowser.create()
。
let