首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将编译的角模板传递给HereMaps API

将编译的角模板传递给HereMaps API
EN

Stack Overflow用户
提问于 2019-10-18 08:20:13
回答 2查看 81关注 0票数 0

我在我的角度应用程序中使用HereMaps,到目前为止,它运行得很好。我当前的问题是,H.ui.InfoBubble组件只接受普通的html,而不接受角模板。

代码语言:javascript
复制
 let bubble = new H.ui.InfoBubble(
      { lat: data.ride.position.latitude, lng: data.ride.position.longitude },
      // this is currently unfortunately not working, the content gets copied 1:1
      { content: '<app-my-angular-component></app-my-angular-component>'}

我考虑过在一生中编译模板,但在这里没有成功。

谢谢你的帮忙!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-10-18 08:34:03

您可以传递一个DOM树节点,而不是用HTML传递字符串。因此,您可以获取和组件nativeElement并将其传递给函数。您可以动态创建组件,然后从DOM树中删除它,最后将它传递给气泡。

我做这件事没有什么经验,所以我无法提供例子

票数 0
EN

Stack Overflow用户

发布于 2019-10-22 13:52:27

谢谢你的提示:kvetis!

这些是取得成果的必要步骤:

代码语言:javascript
复制
// 1. Add your bubble component to entryComponents
...
entryComponents: [BubbleComponent]
...

// 2. Add these includes
import { Component, OnInit, ViewChild, ElementRef, ViewContainerRef,    
    ComponentFactoryResolver } from '@angular/core';

// 3. Init your Viewchild
@ViewChild("map", { static:false, read: ViewContainerRef }) mapContainer: 
    ViewContainerRef

// 4. Create the "factory" on your bubbleComponent in ngOnInit
this.factory = this.resolver.resolveComponentFactory(BubbleComponent);

// 5. Create your component dynamically and it to your Dommarker
let componentRef = this.mapContainer.createComponent(this.factory);
let bubble = new H.ui.InfoBubble(
{ lat: data.ride.position.latitude, lng: data.ride.position.longitude },
   // The FO property holds the province name.
   {
      content: componentRef.location.nativeElement
});

// 6. Don't forget to destroy your component refs on destroy

更多信息可以找到这里

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

https://stackoverflow.com/questions/58446757

复制
相关文章

相似问题

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