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