Konstantin Stupnik Konstantin Stupnik - 1 month ago 18
TypeScript Question

Angular 2: how to bind a subcomponent to property

How can I bind subcomponent mainmenu in template to property menu?

import { Component } from '@angular/core';

import { MainMenuComponent } from './main-menu.component';

@Component({
selector: 'my-app',
template: `
<div class="centered">
<mainmenu></mainmenu>
</div>
`
})
export class AppComponent {
menu: MainMenuComponent;
}

Answer

With the ViewChild annotation:

export class AppComponent {
  @ViewChild(MainMenuComponent) menu: MainMenuComponent;
}
Comments