ionic4(angular)中如何引入第三方js代碼庫?

1  把js文件放到src/assets目錄下。例如我的js文件爲 remogeo.js

 

2  在src目錄下的index.html中增加如下語句:

   <script type="text/javascript" src="assets/remogeo.js"></script>

 

3 在需要調用js代碼的地方作如何聲明:declare var RemoGeoLocation :any;  其中的RemoGeoLocation是根據 remogeo.js中的函數名定義的。下面是我的 remogeo.js中代碼:

function RemoGeoLocation() {
    this._remoteSvrUrl = 'https://webapi.amap.com/html/geolocate.html';

    this._callbackList = [];

    this._seqBase = 1;

    this._frameReady = 0;

    this._watchIdMap = {};
}

RemoGeoLocation.prototype = {

    _getSeq: function() {
        return this._seqBase++;
    }}

如何調用js文件中的方法呢?如下:

var remoGeo = new RemoGeoLocation();

console.log("-1-1:"+ remoGeo._getSeq());//會打印結果 1

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章