在我的angular 2应用程序中,我有一个与onClick事件绑定的leaflet地图和弹出窗口。
弹出窗口的内容包含指向angular组件的链接。然而,当我在.setContent()函数中使用routerLink时,链接不会显示。
我猜这是因为.setContent()无法呈现Angular 2指令,这很合理。我应该使用什么替代方法?
@Component({
selector: 'app-map',
templateUrl: './map.component.html',
styleUrls: ['./map.component.css']
})
export class MapComponent implements AfterViewInit {
openmap: any;
constructor() { }
ngAfterViewInit() {
let openmap = L.tileLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/{z}/{y}/{x}", {
attribution: 'terms and feedback'
});
let map = L.map("map", {
center: [33.2148, -97.1331],
zoom: 5,
zoomControl: true,
maxZoom: 18
}).addLayer(openmap);
let marker = L.marker([39.2148, -98.1331]).addTo(map);
let popup = L.popup();
function onMapClick(e) {
popup
.setLatLng(e.latlng)
.setContent("Facility" + "<br/>" + "<a routerLink='/view2'>" + "View Two" + "</a>")
.openOn(map);
}
map.on('click', onMapClick);
}
}
毋庸置疑,如果我将其改为,那么……
.setContent("Facility" + "<br/>" + "<a href='../view2'>" + "View Two" + "</a>")
这样做可以实现我想要的功能,但会导致页面刷新,因此不是一个好选择。