I know the question title is very general so I'll give the details.
Component:
export class MaterialDetailComponent implements OnInit {
originalMaterialsData: Material[];
currentMaterialData: Material[];
constructor(private _route: ActivatedRoute, public dataService:DataService) { }
ngOnInit() {
let id = +this._route.snapshot.paramMap.get('id');
this.dataService.getMaterialData().subscribe((response) => {
this.originalMaterialsData = response;
});
for(let i = 0; i < this.originalMaterialsData.length; i++) {
if(this.originalMaterialsData[i].id = id) {
this.currentMaterialData.push(this.originalMaterialsData[i]);
}
}
}
}
I'm trying to get the matched object with an id from originalMaterialsData
(array of objects) and assign it to currentMaterialData
so that I'm able to use this one particular object in my component. But it keeps returning undefined
even though I tried many ways to differently write it.