Im try to create a simple page and I have this problem when I I try to show my json file in my component.html
This is the json file.
{
"example": {
"cat": [
{
"title": "title 1",
"href": "#cat0"
},
{
"title": "title 1",
"href": "#cat1"
},
{
"title": "title 1",
"href": "#cat1"
},
{
"title": "title 1",
"href": "#cat1"
},
{
"title": "title 1",
"href": "#cat1"
}
]
}
}
This is the Interface.
export interface menuExample {
example?:{
cat?:{
title: string,
href: string
}
}
}
This is the Service.
export class serviceMenu {
info: menuExample= {};
cargada = false;
team: any[] = [];
constructor( private http: HttpClient) {
this.loadMenu();
}
private loadMenu() {
this.http.get('assets/json/file.json')
.subscribe( (resp: any[]) => {
this.cargada = true;
this.team = resp;
});
}
}
And this is the html file
<li *ngFor="let menudetails of serviceMenu.info.example?.cat" class="side-nav__item">
<a href="{{menudetails.href}}" class="side-nav__link">
<span>{{menudetails.title}}</span>
</a>
</li>
Then I import my file and I did all but I don't understand the mistake :S
ERROR Error: StaticInjectorError(AppModule)[HeaderComponent -> serviceMenu ]:
StaticInjectorError(Platform: core)[HeaderComponent -> serviceMenu ]:
NullInjectorError: No provider for serviceMenu !
Only I try to show my json with an NgFor and show the title and href, nothing else. Someone could help me or provide a better and easy solution? Thanks a lot!
Estefa