aleczandru
aleczandru

Reputation: 5449

Achieving Interpolation in Angular 2

Hi I am new to angular 2 and typescript and am trying to add html inside the tags of a component. This is what I have so far:

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

export class Chart {
}

The html has the following strcuture:

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

What I would like is to use the component in the following way:

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

When angular parses this code it should display the following:

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

In angular 1 this was achieved via directive interpolation.Is there any way to achieve this in angular 2?

Upvotes: 1

Views: 353

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657148

chart.component.html should look like

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

to achieve what you want.

Upvotes: 4

Related Questions