Angular2 Html inside a Component

Bünyamin Sarıgül :

I want create a component like a template. For example, instead of writing this everywhere:

<div class="myClass">
    <div class="myHeader" id="headerId"> Title </div>
    <div class="myContent" id="contentId"> <<Some HTML code>> </div>
</div>

I want to use a component like:

<my-component title="Title" headerID=headerId contentID=contentID>
    <<Some HTML code>>
</my-component>

How can I implement something like these in Angular2?

j2L4e :

Use <ng-content></ng-content> in your component.

my.component.html

<div class="myClass">
    <div class="myHeader" id="headerId"> Title </div>
    <div class="myContent" id="contentId"> <ng-content></ng-content> </div>
</div>

parent.component.html

<my-component title="Title" headerID=headerId contentID=contentID>
    <<Some HTML code>>
</my-component>

Whatever is inside <my-component></mycomponent> will be rendered in <ng-content></ng-content>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Angular2: Cloning component / HTML element and it's functionality

How to show a HTML Dom/ Angular Component inside a Angular component?

How to put a component inside another component in Angular2?

Angular 2 - formControlName inside component

Angular2 : two way binding inside parent/child component

Redirect to a different component inside @CanActivate in Angular2

Custom angular2 form input component with two way binding and validation inside a component

Angular2 Component inside ngFor throws Error (viewFactory is not a function)

Angular2 component based on canvas : how to draw inside?

Can we use a component inside another component in current version of Angular2?

Angular2: How to show inner HTML of component-tags inside of component?

Call a component method from HTML in Angular2

Angular2, evaluate template from string inside a component

Extending a PrimeNg component inside Angular2

dhtmlx inside angular2 component

component inside component Angular

Angular2: loop typescript dictionary in html component

Is it possible to have HTML content inside an Angular Component?

Angular2 replacing component dynamically inside another component

Angular2 Dart - Get Text inside Angular2 Component

Angular2 localization reload component HTML

Angular2 reference component inside another component

Angular2: get reference of html element inside component and then Scroll to top that html element

Angular2 component with selector not in the html

Angular2 Component's Context inside jQuery timpicker method

What is the meaning of # inside an Angular2 HTML directive

html wont render from inside angular 2 component

How to set a component's html to iframe in Angular2

NativeScript - Angular HTML component inside WebView