我正在尝试将数据从父组件传递到子组件,但是我得到的数据是不确定的, 在我下面的代码中
父组件
在这里我在使用中声明的part_data
this._PartService.GetDataValues(this.search.item, this.search.filter_type, release_part).subscribe(
result => {
this.resultData = result;
this._PartService.part_data = this.resultData.data
})
子组件
我在这里使用观察者
this.searchService.observer.subscribe(search => {
this.part = search.item;
this.specification = this._PartService.part_data.partMasterDataCompleteList[0];
})
我在这里得到“ PartMasterDataCompleteList [0]未定义”
答案 0 :(得分:1)
将此用作子组件:-
@Component({
selector: 'app-hero-detail',
templateUrl: './hero-detail.component.html',
styleUrls: ['./hero-detail.component.css']
})
export class HeroDetailComponent implements OnInit {
@Input() hero: Hero;
constructor() {}
ngOnInit() {}
}
当您需要向组件馈送数据时,请使用以下代码:-
<app-hero-detail [hero]="selectedHero"></app-hero-detail>
hero属性是@Input
,它从外部环境接收数据。
有关更多信息,请参阅Angular教程:-
答案 1 :(得分:-1)