[英]Angular 2/4 Bing Map pushpin custom template function call
I have problem to fit my pushpin custom template into angular component. 我在将图钉自定义模板适合角度组件时遇到问题。
My component: 我的组件:
import { Component, AfterViewInit } from '@angular/core';
@Component({
selector: 'app-map',
templateUrl: './map.component.html',
styleUrls: ['./map.component.scss']
})
export class MapComponent implements, AfterViewInit {
@ViewChild('myMap') myMap;
map: any;
infoboxClick;
infoboxTemplate = `<div id="infoboxText" class="custom-infobox">
<span class ="close-sighn" onclick="closeCustomInfoBox()">x</span>
{description}
</div>`;
constructor(private dataService: MapService) {
}
ngAfterViewInit() {
this.getMap();
}
getMap() {
if ((window as any).Microsoft && (window as any).Microsoft.Maps) {
this.map = new (window as any).Microsoft.Maps.Map(document.getElementById('mapId'), {
credentials: ''
});
var pushpin = new (window as any).Microsoft.Maps.Pushpin(map.getCenter(), null);
(window as any).Microsoft.Maps.Events.addHandler(pushpin, 'click', (args) => {
this.infoboxClick.setOptions({
location: args.target.getLocation(),
htmlContent: this.infoboxTemplate.replace('{description}', 'Some test description'),
visible: true
});
});
map.entities.push(pushpin);
} else {
setTimeout(() => { this.getMap() }, 1000);
}
}
closeCustomInfoBox() {
this.infoboxClick.setOptions({
visible: false
});
}
}
My view: 我的观点:
<div #myMap id="mapId" class="map-container"></div>
In infoboxTemplate I have function 'closeCustomInfoBox()', which should close infobox. 在infoboxTemplate中,我具有函数'closeCustomInfoBox()',该函数应关闭infobox。
1) How I can call that function from my angular component? 1)如何从角度组件中调用该函数?
2) I need to get proper angular scope if I call it how I can get approach to my 'infoboxClick' variables? 2)如果我将其称为“ infoboxClick”变量,该如何获得合适的角度范围?
If you mean you want to access closeCustomInfoBox() function and infoboxClick variable from the parent component. 如果您要访问父组件,请访问closeCustomInfoBox()函数和infoboxClick变量。
Check this https://angular.io/guide/component-interaction#parent-interacts-with-child-via-local-variable 检查此https://angular.io/guide/component-interaction#parent-interacts-with-child-via-local-variable
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.