[英]How to call typescript function from external javascript function
Ionic2項目。 我在打字稿中使用了InAppBrowser,而Webview是基於tomcat服務器的。 我想從外部javascript函數調用打字稿功能。 我該如何調用該函數? 在我的代碼下面。
import { Component, ViewChild, ElementRef } from '@angular/core';
import { NavController, Content } from 'ionic-angular';
import { InAppBrowser } from '@ionic-native/in-app-browser';
import * as $ from 'jquery';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
@ViewChild(Content) content: Content;
constructor(public navCtrl: NavController, private iab: InAppBrowser,
private elementRef : ElementRef) {
var ref = window.open(url, '_self', 'location=yes');
}
}
function getGPS(e):string { //the function returns a string
return "client getGPS func" ;
}
我只想在javascript函數中調用getGPS函數。 這是我的JavaScript代碼。
umn2={
getGPS: function(){
document.getElementById("resultArea").value = //that is client part
}
};
請告訴我解決方案。 謝謝。
必須先將TypeScript編譯為Javascript。 因此,第一步就是要驗證這一點。
其次,這是getGPS函數的2種不同實現。 一個定義在umn2
對象上, umn2
定義在Typescript代碼中。 我認為它應該從typescript模塊導出,以便可以從外部導入/使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.