0
私はasp.netコアスパ角度アプリケーションでgoogleマップを実装することができますが、私は私のindex.cshtmlにスクリプトを含んでいますが、角度からアクセスしている間にエラーが発生しました。asp.netコア2.0スパ角度+ googleマップ
import { Component } from '@angular/core';
declare var google: any;
@Component({
selector: 'home',
templateUrl: './home.component.html'
})
export class HomeComponent {
constructor() {
var mapProp = {
center: new google.maps.LatLng(51.508742, -0.120850),
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
}
}
Index.html
@{
ViewData["Title"] = "Home Page";
}
<app asp-prerender-module="ClientApp/dist/main-server">Loading...</app>
<script src="https://maps.googleapis.com/maps/api/js?key=[YOUR-KEY]" async defer></script>
<script src="~/dist/vendor.js" asp-append-version="true"></script>
@section scripts {
<script src="~/dist/main-client.js" asp-append-version="true"></script>
}
要求の処理中に未処理の例外が発生しました。
NodeInvocationException: Uncaught (in promise): ReferenceError: google is not defined ReferenceError: google is not defined at new HomeComponent (F:\yo\ClientApp\dist\main-server.js:16281:25)
エラー?それが何だった。 – k11k2
要求の処理中に未処理の例外が発生しました。 NodeInvocationException:未知(約束):ReferenceError:googleが定義されていません ReferenceError:googleが定義されていません 新しいHomeComponent(F:\ yo \ ClientApp \ dist \ main-server.js:16281:25) –
あなたがロードしています'AppComponent'に関連している' 'は' AppComponent'に 'var google:any any'を宣言し、それをローカル記憶域に保存し、いつでもどこでも使えるようにする必要があります。 –
k11k2