【发布时间】:2016-12-27 04:32:10
【问题描述】:
我在 how to create dynamic components 上遵循 Günter Zöchbauer 的建议 我想知道如何将值传递给它 - 例如,子组件有一个@input。
使用上述问题中给出的 plunker 示例 - plunker - 我如何向子组件传递一个字符串,我们称之为消息,然后在单击“添加”按钮时显示。
以下是子组件外观的示例:
import {Component OnChanges, Input} from '@angular/core'
@Component({
selector: 'hello',
providers: [],
template: `<h1>{{message}}</h1>`,
directives: []
})
export class HelloComponent implements OnChanges {
@Input() message:any;
constructor() {
}
ngOnChanges(changes:any){
}
}
【问题讨论】:
标签: angular angular2-directives