我尝试在Angular中集成Google地图.
的index.html
<script async defer src="https://maps.googleapis.com/maps/api/js?key=api_key&callback=initMap"></script>
Run Code Online (Sandbox Code Playgroud)
example.component.html
...
<div id="map"></div>
...
Run Code Online (Sandbox Code Playgroud)
example.component.ts
...
ngAfterViewInit() {
function initMap() {
var uluru = {lat: -25.363, lng: 131.044};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: uluru
});
var marker = new google.maps.Marker({
position: uluru,
map: map
});
}
}
Run Code Online (Sandbox Code Playgroud)
我仍然得到错误"initMap不是一个函数".
当我提交表单时,我想导航到另一个站点并将 URL 中的搜索值设置为参数。
我有以下代码:
searchOffers() {
this.router.navigate([
'/search?query= +
this.search.value.FG
]);
}
Run Code Online (Sandbox Code Playgroud)
此代码有效,但路由后的 URL 如下所示。
localhost:4200/search%3Fquery%3D1
Run Code Online (Sandbox Code Playgroud)
(query参数值为1)。
使用此 URL,我无法获取参数。
如何将 URL 格式化为:localhost:4200/search?query=1?
我有一个数组,其中包含商品有图像名称的信息.随着*ngIf它应该显示任何图像或"无图像".但内部的属性绑定*ngIf不起作用.这甚至可能吗?
<div class="m-c-o" *ngFor="let offer of offers">
<div class="m-c-p" *ngIf="showOffers">
<div class="m-c-img-c">
<img *ngIf="{{ offer.U_D__IMAGE }} != false" src="{{ imagePath + offer.U_D__IMAGE }}">
<div *ngIf="{{ offer.U_D__IMAGE }} === false">
<i class="materials-icons">photo_camera</i>
<div class="m-c-img-ni">No Images</div>
</div>
</div>
</div>
</div
Run Code Online (Sandbox Code Playgroud)