I am making a form to create an account and I am faced with the following problem.
The first thing I do is go to find the json to an api that at the moment I have the json locally in assets,
This is the method of the service that is responsible for searching the json
getJoinCustomer():Observable<JoinCustomer>{
return this.http
.get(this._url).pipe(
map((res:Response)=>res.json())
)
}
Then in my component I inject the service and I call it within a method to map it to my property.
getJoinCustomer():void{
this._joinService.getJoinCustomer()
.subscribe(joinCustomer => {
this.joinCustomer = joinCustomer;
this.join = new Join(this.joinCustomer.customerID)
})
And I call this method from the
ngOnInit(){
this.getJoinCustomer();
}
And even if I made the model in the following way
{"joinCustomer":[{
"customerID":"ASD123"
}]}
JSON
export class JoinCustomer{
customerID:string;
}
JoinCustomer.ts
I get the error
TypeError: Can not read property 'customerID' of undefined