Angular 2:如何将子组件绑定到property

时间:2016-10-18 11:20:57

标签: angular typescript angular2-components

如何将模板中的子组件mainmenu绑定到属性菜单?

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;
}

1 个答案:

答案 0 :(得分:2)

使用ViewChild注释:

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