I've seen working examples when <ng-content>
is beeing used inside other nested components (like here) but I haven't managed to run it inside a root Angular2 component:
HTML template:
<html>
<body>
<app>
<h1>Hello, World!</h1>
</app>
</body>
</html>
Angular 2 component in TypeScript:
import {Component, View, bootstrap} from 'angular2/angular2';
@Component({
selector: 'app'
})
@View({
template: 'Header: <ng-content></ng-content>',
})
export class App {
}
bootstrap(App);
I'd expect that this will generate:
<app>
Header: <h1>Hello, World!</h1>
</app>
but it doesn't and the content of <app>
is ignored. See demo on Plunker.
I thought maybe this goes against some Angular 2 philosophy or something so it's not even supported, but my use case is very similar to the first working demo I think.