Hey there, I'm currently working with Angular 2 and trying to log a simple JSON object in the console. However, I keep encountering this issue https://i.stack.imgur.com/A5NWi.png
UPDATE...
Below is my error log for reference
https://i.stack.imgur.com/eCXHe.png
I've searched through several resources and came across similar problems like
Getting [object Object] while mapping http response in Angular 2
Despite making some changes, I still can't seem to resolve it!
Firstly, let me share my items2.json file
{
"Company": {
"company_details": [
{
"test": "test"
}
],
"success": true
}
}
This is my model 'company.ts'
export interface Company {
company_details : CompanyDetails[];
success : boolean;
}
export interface CompanyDetails {
test: string;
}
Now, here's my component:
import {Component, OnInit} from '@angular/core';
import {Company} from "./models/test/company";
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent implements OnInit{
title = 'Test angular';
constructor(private http : HttpClient) {}
ngOnInit(): void {
this.http.get<Company>('http://localhost:4200/assets/items2.json')
.subscribe( data => console.log(data.company_details)
);
}
}
Could someone please help me understand why I'm getting this error? Any suggestions on how to fix it would be greatly appreciated.
Thank you!