I am working in an Angular4 application ,In this I am trying to receive json data in my component file .But I got undefined as response.
Json structure
Service File
get_New_Products():Observable<Products[]>{
this.productServiceURL = `http://localhost:abc/api/data/Get_Product`;
return this.http.get<Products[]>(this.productServiceURL);
}
In service file I got the outcome by using the following line of code
console.log(data); //output : Array of data
For Specific data
console.log(data[0]['PRODUCT_NAME']); // output : iPhone
Component File
ngOnInit() {
this.CartdataService.get_New_Products();
this.CartdataService.get_New_Products()
.subscribe(
data => {
this.products_Id = data['PRODUCT_ID'];
this.product_Name = data['PRODUCT_NAME'];
this.products_Price = data['PRODUCT_PRICE'];
this.products_Image=data['PRODUCT_IMAGE']
this.products_Image_Onhover=data['PRODUCT_IMAGE_ONHOVER']
console.log(this.product_Name);
});
}
Here I can't reach the data .I want to bind all the PRODUCT_ID,PRODUCT_NAME..etc in a single variable.I think the way I am trying to get data is wrong.
I must do some magic in these lines ,
this.products_Id = data['PRODUCT_ID'];
this.product_Name = data['PRODUCT_NAME'];
this.products_Price = data['PRODUCT_PRICE'];
this.products_Image=data['PRODUCT_IMAGE']
this.products_Image_Onhover=data['PRODUCT_IMAGE_ONHOVER']
Model File
export interface Products{
PRODUCT_ID :string[];
PRODUCT_NAME : string[];
PRODUCT_PRICE : string[];
PRODUCT_IMAGE : string[];
PRODUCT_IMAGE_ONHOVER : string[];
}
Please help me to solve this issue.