【发布时间】:2018-01-11 03:53:54
【问题描述】:
我正在使用 NativeScripts angular 在我的应用程序中创建一个 Web 视图。当我单击 Web 视图中的按钮时,我想在浏览器中打开一个网页。
This post shows how to do it using swift 并且我可以在我的iOS project using the marshaling technique 中使用本机库,但我在转换为 Typescript 时遇到了困难。
ngOnInit(): void {
if(isIOS)
{
let webView = UIWebView;
let loadREquest = NSURLRequest;
let navType = UIWebViewNavigationType.LinkClicked;
}
}
我的第二次尝试是使用this plugin,但我不确定如何在我的网络视图中点击特定元素时监听点击事件。
import {Component, OnInit, ElementRef, AfterViewInit } from "@angular/core";
import {WebView, LoadEventData} from "ui/web-view";
import { Page } from "tns-core-modules/ui/page";
import {isAndroid, isIOS} from "platform";
let webViewInterfaceModule = require('nativescript-webview-interface');
import * as utils from 'utils/utils';
export class AboutComponent implements OnInit, AfterViewInit {
@ViewChild('webview') webView: ElementRef;
private oLangWebViewInterface;
constructor(private page: Page){}
ngAfterViewInit() {
this.setupWebViewInterface();
}
private setupWebViewInterface() {
let webView: WebView = this.webView.nativeElement;
this.oLangWebViewInterface = new webViewInterfaceModule.WebViewInterface(webView, 'http://myurl.net/about');
//Is it possible to structure this to listen for the click of an element in my web view with id of #navigate
this.oLangWebViewInterface.on('click', function(eventData){
utils.openUrl('https://energy.gov');
});
}
【问题讨论】:
-
要在浏览器中打开网址吗?
-
是的,在单击 Web 视图内的链接时
标签: ios nativescript angular2-nativescript