我的部件結構是這樣的角2 - 通如何值循環到內部部件時
Parent.ts
@Component({
template: `
<div *ngFor="let i of optionCollection; let index = index; trackBy: trackByFn">
<Child></Child>
<button type="submit" class="btn btn-primary">Create</button>
</div>
`,
})
export class Parent {
}
Child.ts
@Component({
selector: 'Child'
template: `
<input />
`,
})
export class Child {
indexValueFromParent:any
}
如何能我將父項的索引值傳遞給子組件,並將該值分配給子項的var indexValueFromParent
使用viewChild https://angular.io/docs/ TS /最新/菜譜/組件communication.html#!#母公司查看的孩子 –