【发布时间】:2017-06-05 13:43:07
【问题描述】:
该绑定适用于标题、副标题、button.icon 和 button.name,但不适用于 button.action
parent.component.html
<app-title [title]="title" [subtitle]="subtitle" [buttons]="buttons"></app-title>
parent.component.ts
export class ParentComponent {
actionOne() {
...
}
title = 'Title';
subtitle = 'Subtitle';
buttons = [
{ 'name': 'Name1', 'icon': 'Icon1', 'action': 'actionOne()'},
{ 'name': 'Name2', 'icon': 'Icon2', 'action': 'actionTwo()'},
{ 'name': 'Name3', 'icon': 'Icon3', 'action': 'actionThree()'}
];
}
child.component.html
<section>
<div class="text-wrapper">
<h1>{{ title }}</h1>
<h2 *ngIf="subtitle">{{ subtitle }}</h2>
</div>
<template *ngIf="buttons">
<div class="buttons-wrapper">
<button *ngFor="let button of buttons" md-raised-button (click)="button.action"><md-icon *ngIf="button.icon">{{ button.icon }}</md-icon>{{ button.name }}</button>
</div>
</template>
</div>
child.component.ts
export class ChildComponent {
@Input() title:string;
@Input() subtitle:string;
@Input() buttons:string;
}
【问题讨论】:
标签: angular binding components bind communication