Ad
Angular Component Inside Angular Component? ` `
I've tried with ng-template
and with ng-container
, but I can't figure out how to include a component inside a component…
import { Component } from '@angular/core';
@Component({
selector: 'hello',
// template: `<h1>Hello</h1><div>I am in a div<ng-container></ng-container>; now this is end</div>`,
template: `<h1>Hello</h1><div>I am in a div<ng-template></ng-template>; now this is end</div>`,
styles: [`h1 { font-family: Lato; }`]
})
export class HelloComponent {}
@Component({
selector: 'intestines',
template: 'Eww',
styles: []
})
export class IntestinesComponent {}
@Component({
selector: 'my-app',
template: `<hello><intestines></intestines></hello>`,
styles: [ 'p { font-family: Lato; }' ]
})
export class AppComponent {}
Ad
Answer
Use ng-content
@Component({
selector: 'hello',
template: `<h1>Hello</h1><div>I am in a div<ng-content></ng-content>; now this is end</div>`,
styles: [`h1 { font-family: Lato; }`]
})
export class HelloComponent {}
Also check this article may be useful for you.
Ad
source: stackoverflow.com
Related Questions
- → Make a Laravel collection into angular array (octobercms)
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → Angularjs not working inside laravel form
- → Analysis of Flux implementations
- → how to write react component to construct HTML DOM
- → angular ng-repeat and images in a row
- → Conditional BG Color on AngularJS
- → Should I 'use strict' for every single javascript function I write?
- → getting the correct record in Angular with a json feed and passed data
- → "Undefined is not a function" at .toBe fucntion
- → angularjs data binding issue
- → Angular / JavaScript auto hydrate an instance
- → Convert generic text string in json object into valid url using Angular
Ad