So Yeon  Shin
So Yeon Shin

Reputation: 85

How to import js file in typescript?

I want to import js file in typescript. And I want to access object and function in the js files. Also I added js file in index.html but It doesn't working too. so I find a clue that "import '[js file path]'" but it doesn't working.

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { NavParams } from 'ionic-angular';
import '../../pages/mobile.js';


@Component({
  selector: 'page-success',
  templateUrl: 'success.html'
})

export class SuccessPage {
  constructor(public navCtrl: NavController, public navParms: NavParams) {

let centerPos =  new atlan.maps.UTMK(953933.75, 1952050.75);

 }
}

This is success.ts file. I want to find 'atlan' object. Give me a solution please. Thx a lot!

Upvotes: 2

Views: 27097

Answers (2)

Eddie Martinez
Eddie Martinez

Reputation: 13910

You have to use the declare keyword so you do not get any compilation errors. You can do the following

    import { Component } from '@angular/core';
     ....
    /* Here you are telling typescript compiler to 
       ignore this variable it did not originate with typescript.*/
    declare var atlan: any; 

    @Component({
      selector: 'page-success',
      templateUrl: 'success.html'
    })

export class SuccessPage {
    ....
}

Upvotes: 8

sjahan
sjahan

Reputation: 5960

In your file ../../pages/mobile.js, you must export your atlan object (if you can edit this file of course), then, you import it the same way you do with everything.

Upvotes: 1

Related Questions