Slip Slip - 19 days ago 8
TypeScript Question

Why does my template not work in angular2 component?

I have 2 components

first

import {Component} from 'angular2/angular2';
import {Navbar} from './navbar';
@Component({
selector: 'app'
template: `<div class="col-md-12">
<navbar></navbar>
</div>`
})
export class App {}


and second

import {Component} from 'angular2/angular2';
@Component({
selector: 'navbar',
template:`<p>Navbar</p>`
})
export class Navbar {}


But in root (App) component doesn't show navbar. What am I missing?

Plunkr

Answer

You need to add NavBar into the directives attribute:

@Component({
  selector: 'app'
  template: `<div class="col-md-12">
    <navbar></navbar>
    </div>`,
  directives: [ Navbar ]
})