繁体   English   中英

如何从外部javascript函数调用Typescript函数

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM