gpt4 book ai didi

asp.net core 2.0 spa angular + 谷歌地图

转载 作者:太空狗 更新时间:2023-10-29 18:01:30 24 4
gpt4 key购买 nike

我如何在 asp.net core spa angular 应用程序中实现 google map,我已经将脚本包含在我的 index.cshtml 中,但是从 angular 访问它时出错。

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)

最佳答案

.cshtml

<app asp-prerender-module="ClientApp/dist/main-server"
asp-prerender-data='@ViewData["token"]' >Loading...</app>//Storing

<script src="~/dist/vendor.js" asp-append-version="true"></script>
@section scripts {
<script src="~/dist/main-client.js" asp-append-version="true"></script>
}

boot.server.ts

setImmediate(() => {
resolve({
html: state.renderToString(),

globals: {
tokenData: params.data
}

});

应用程序组件.ts

declare var tokenData: any;
@Component({..})
export class AppComponent implements OnInit{
ngOnInit() {
let accessToken = tokenData;
localStorage.setItem('token', accessToken);
}
}

关于asp.net core 2.0 spa angular + 谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46088594/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com