[英]Uncaught (in promise): Error: Module parse failed: Unexpected token (91:0) You may need an appropriate loader to handle this file type
I am testing angular map api for tracking place in a search box field on Ionic 3. 我正在测试用于跟踪Ionic 3上搜索框字段中位置的角度地图api。
I don't know how to solve this problem "Uncaught (in promise): Error: Module parse failed: Unexpected token (91:0) You may need an appropriate loader to handle this file type." 我不知道如何解决此问题“未捕获(承诺):错误:模块解析失败:意外令牌(91:0)您可能需要适当的加载程序来处理此文件类型。” Apreciate any help please.
请感谢任何帮助。
Ts file ts文件
import { Component, ViewChild, ElementRef, NgZone } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { TranslateService } from '@ngx-translate/core';
//Import for Search box
import {FormControl} from "@angular/forms";
import { } from 'googlemaps';
import { MapsAPILoader } from '@agm/core';
//declare var google: any;
@IonicPage()
@Component({
selector: 'page-map',
templateUrl: 'map.html'
})
export class MapPage {
public latitude: number;
public longitude: number;
public searchControl: FormControl;
public zoom: number;
@ViewChild("search")
public searchElementRef;
constructor(public navCtrl: NavController, public navParams: NavParams,
private mapsAPILoader: MapsAPILoader, private ngZone: NgZone) {
this.zoom = 4;
this.latitude = 39.8282;
this.longitude = -98.5795;
//create search FormControl
this.searchControl = new FormControl();
//set current position
this.setCurrentPosition();
}
ionViewDidLoad() {
//set google maps defaults
this.zoom = 4;
this.latitude = 39.8282;
this.longitude = -98.5795;
//create search FormControl
this.searchControl = new FormControl();
//set current position
this.setCurrentPosition();
//load Places Autocomplete
this.mapsAPILoader.load().then(() => {
let nativeHomeInputBox =
document.getElementById('txtHome').getElementsByTagName('input')[0];
let autocomplete = new
google.maps.places.Autocomplete(nativeHomeInputBox, {
types: ["address"]
});
autocomplete.addListener("place_changed", () => {
this.ngZone.run(() => {
//get the place result
let place: google.maps.places.PlaceResult =
autocomplete.getPlace();
//verify result
if (place.geometry === undefined || place.geometry ===
null) {
return;
}
//set latitude, longitude and zoom
this.latitude = place.geometry.location.lat();
this.longitude = place.geometry.location.lng();
this.zoom = 12;
});
});
});
}
private setCurrentPosition() {
if ("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition((position) => {
this.latitude = position.coords.latitude;
this.longitude = position.coords.longitude;
this.zoom = 12;
});
}
}
}
HTML file HTML文件
<ion-header>
<ion-navbar>
<!--<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>-->
<ion-title>Kokua</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<!-- "no borders" "transparent" "fullscreen="true"" "<div #map id="map">
</div>" -->
<ion-item>
<ion-label floating>Enter Address</ion-label>
<ion-input id="txtHome" type="text"></ion-input>
</ion-item>
<agm-map [latitude]="latitude" [longitude]="longitude"
[scrollwheel]="false" [zoom]="zoom">
<agm-marker [latitude]="latitude" [longitude]="longitude"></agm-marker>
</agm-map>
</ion-content>
I had the same error, not in a .html but in the .ts file. 我有同样的错误,不是在.html中,而是在.ts文件中。
The "problem" was that I'd a very long comment /* */ to keep the entire old version of that .ts file. “问题”是我要很长的注释/ * * /来保留该.ts文件的整个旧版本。 The comment was fine, with no one part outside of it;
评论很好,没有多余的一部分。 but very long.
但是很长
Just deleting that very long comment solved that. 只需删除很长的评论即可解决。
The solution that I found was unexpected and simple. 我发现的解决方案出乎意料且简单。 I just clean the cash and the trash of my code, like comments and imports never used.
我只是清理代码中的现金和垃圾,例如从未使用过的注释和导入。 Then the code worked perfectly.
然后,代码运行完美。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.