1

Ionic2 project. I used InAppBrowser in typescript and webview is based on tomcat server. I want to call typescript funtion from external javascript function. How can i call that function? Below my code.

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

I just want to call getGPS function in javascript function. This is my javascript code.

umn2={
    getGPS: function(){
        document.getElementById("resultArea").value = //that is client part
    }
 };

Please tell me the solutions. Thank you.

So Yeon Shin
  • 85
  • 1
  • 1
  • 5
  • Possible duplicate of [Calling properly TypeScript code from JavaScript](https://stackoverflow.com/questions/26427722/calling-properly-typescript-code-from-javascript) – Philip Brack Nov 01 '17 at 15:20

1 Answers1

0

The TypeScript has to be compiled first to Javascript. So the first step is to verify that.

Second this is that you have 2 different implementation of getGPS functions. One is defined on the umn2 object and the other is in the Typescript code. I think it should be exported from the typescript module, to be importable/usable from outside.

David Votrubec
  • 3,968
  • 3
  • 33
  • 44