So *_*hin 2 javascript typescript ionic2 angular
我想在typescript中导入js文件.我想访问js文件中的对象和函数.我还在index.html中添加了js文件,但它也没有用.所以我找到了"导入'[js文件路径]'"的线索,但它不起作用.
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);
}
}
Run Code Online (Sandbox Code Playgroud)
这是success.ts文件.我想找到'atlan'对象.请给我一个解决方案.多谢!
您必须使用declare关键字,这样您才不会收到任何编译错误.您可以执行以下操作
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 {
....
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16985 次 |
| 最近记录: |