Okay so I am running angular 2, and I am just trying to log a simple JSON object in the console but I get this
UPDATE...
I have provided my error log below
I have looked on a fair few posts and people have similar issues e.g
Getting [object Object] while mapping http response in Angular 2
I have changed a few things around but still no dice!
Firstly here is my items2.json
{
"Company": {
"company_details": [
{
"test": "test"
}
],
"success": true
}
}
My model ... 'company.ts'
export interface Company {
company_details : CompanyDetails[];
success : boolean;
}
export interface CompanyDetails {
test: string;
}
Here is 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)
);
}
}
Why I am receiving this error? how do I fix it ?
Thanks