2017-11-01 22 views
1

Ionic2プロジェクト。私はtypescriptでInAppBrowserを使用し、webviewはtomcatサーバーに基づいています。私は外部JavaScript関数からtypescript関数を呼び出す必要があります。どのように私はその機能を呼び出すことができますか? 私のコードの下に。外部JavaScript関数からtypescript関数を呼び出す方法

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 
    } 
}; 

解決策を教えてください。ありがとうございました。

+0

[JavaScriptから適切にタイプスクリプトコードを呼び出す](https://stackoverflow.com/questions/26427722/calling-properly-typescript-code-from-javascript)の可能な複製 –

答えて

0

TypeScriptは、まずJavascriptにコンパイルする必要があります。だから最初のステップはそれを確認することです。

これは、2つの異なるgetGPS機能が実装されていることです。 1つはumn2オブジェクトで定義され、もう1つはTypescriptコードで定義されています。 私はそれがtypescriptモジュールからエクスポートされ、外部からインポート/使用可能になるべきだと思います。

関連する問題