Hello guys i am using asp.net mvc 5.
When i try to find object by id it returns undefined.Here objects are displayed fine when i do console.log(this.vtypes)
controller.cs:
public JsonResult GetVerificationType(){
List<verificationType> vlist = new List<verificationType>();
vlist.Add(new verificationType() { vType = "vtype1", vtypeID = 1 });
vlist.Add(new verificationType() { vType = "vtype2", vtypeID = 2 });
vlist.Add(new verificationType() { vType = "vtype3", vtypeID = 3 });
return Json(vlist, JsonRequestBehavior.AllowGet);}
typescript file:
export class DashboardComponent implements OnInit {
model: any = {};
vtypes = [];
constructor(private LoginServiceModule: LoginService, private router: Router, ) { }
ngOnInit() {
this.LoginServiceModule.getVerificationTypes().subscribe(x => {
for (let i = 0; i <= x.length - 1; i++) {
this.vtypes.push(x[i]); <--- x[i].vtypeID doesn't work here
}
});
console.log(this.vtypes); <----- works fine shows array of 3 length
var item = this.vtypes.find(x => x.vtypeID === 1);
console.log(item); <---- returns undefined even when vtypeID = 1 is present
}}