0
下面使用@input屬性是我的樣品角2分量代碼在角2
@Component({
selector: 'author-edit',
templateUrl:'./author/edit'
})
export class AuthorEditComponent implements OnInit{
@Input() author: AuthorModel;
fg: FormGroup;
constructor(
public formBuilder: FormBuilder
) {}
ngOnInit() {
alert(this.author.id); // ERROR Cannot read property 'id' of undefined
}
}
}
該組件從父組件中下面使用的提及方式
<author-edit [author]="editAuthor"></author-edit>
在上面的代碼,這是爲什麼我無法訪問「author」輸入屬性的this.author.id值。
editAuthor究竟是什麼? –
'editAuthor'未在父範圍內設置 – VadimB
它是「AuthorModel」類型的對象 – refactor