【问题标题】:Achieving Interpolation in Angular 2在 Angular 2 中实现插值
【发布时间】:2023-04-04 18:02:01
【问题描述】:

您好,我是 angular 2 和 typescript 的新手,我正在尝试在组件的标签中添加 html。这是我目前所拥有的:

Component({
    selector: 'chart',
    templateUrl: './app/chart/chart.component.html'
})

export class Chart {
}

html的结构如下:

<div class='chart-container'></div>

我希望通过以下方式使用该组件:

<chart>
 <p>'Hello World'</p>
</chart>

当 Angular 解析这段代码时,它应该显示以下内容:

  <chart>
     <div class='chart-container'>
          <p>'Hello World'</p>
      </div>
  </chart>

在角度 1 中,这是通过指令插值实现的。有没有办法在角度 2 中实现这一点?

【问题讨论】:

标签: angular typescript


【解决方案1】:

chart.component.html 应该是这样的

  <div class='chart-container'>
      <ng-content></ng-content>
  </div>

实现你想要的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-12
    • 2016-10-23
    • 2017-07-27
    • 2017-09-10
    • 1970-01-01
    • 1970-01-01
    • 2017-06-25
    • 1970-01-01
    相关资源
    最近更新 更多