当使用Angular的@Input
装饰器时,确保以下几点:
@Input
装饰器,并指定了要传递的属性名称。例如:import { Component, Input } from '@angular/core';
@Component({
selector: 'app-child',
template: `
{{ childData }}
`
})
export class ChildComponent {
@Input() childData: string;
}
@Input
属性。例如:
其中,parentData
是父组件中的一个属性,可以是任何类型的数据。
import { Component } from '@angular/core';
@Component({
selector: 'app-parent',
template: `
`
})
export class ParentComponent {
parentData: string = 'Hello from parent component';
}
这样,childData
属性的值将会传递给子组件,并在子组件中显示。