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