首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在google地图中显示自定义标记in angular2

在google地图中显示自定义标记in angular2
EN

Stack Overflow用户
提问于 2017-04-17 09:18:49
回答 1查看 1.8K关注 0票数 4

map.component.ts代码:

代码语言:javascript
复制
......
infoWindow = new google.maps.InfoWindow(
{
    content: `<custom-tag></custom-tag>`    //***not displaying anything***
});
infoWindow.open(map, marker);
......

map.component.html代码:

代码语言:javascript
复制
<custom-tag></custom-tag>      <!--***displays hi***-->
<div class="google-maps"></div>

定制标记.Component.html代码:

代码语言:javascript
复制
<h2>hi</h2>

module.ts、routing.ts文件肯定没有错误。信息窗口只是打开和显示什么,请帮助我找出为什么信息没有显示任何东西。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-17 09:37:48

您必须通过ComponentFactoryResolver动态创建组件。

代码语言:javascript
复制
const compFactory = this.resolver.resolveComponentFactory(CustomTag);
this.compRef = compFactory.create(this.injector);

this.appRef.attachView(this.compRef.hostView);

let div = document.createElement('div');
div.appendChild(this.compRef.location.nativeElement);

this.infoWindow.setContent(div);
this.infoWindow.open(this.map, marker);

这是柱塞实例

不要忘记将CustomTag组件添加到entryComponents

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43448577

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档