I'm trying to access data with ngfor but I can not. How do I get access to each data with ngfor?
json:
[
{
"id": 1,
"name": "Programas",
"base_Url": "http://uol.com.br",
"order": 0,
"programs": [
{
"id": 56,
"name": "Programa 1",
"base_Url": "https://google.com",
"active": true,
"menu_id": 2
},
{
"id": 57,
"name": "Programa ",
"base_Url": "https://google.com",
"active": true,
"menu_id": 2
},
{
"id": 58,
"name": "Programa",
"base_Url": "https://google.com",
"active": true,
"menu_id": 2
}
]
},
{
"id": 2,
"name": "Jornalísticos",
"base_Url": "http://uol.com.br",
"order": 1,
"programs": [
{
"id": 59,
"name": "Programa 2",
"base_Url": "https://google.com",
"active": true,
"menu_id": 2
},
{
"id": 60,
"name": "Programa ",
"base_Url": "https://google.com",
"active": true,
"menu_id": 2
},
{
"id": 61,
"name": "Programa",
"base_Url": "https://google.com",
"active": true,
"menu_id": 2
}
]
}
]
method no service:
list() {
return this.http.get<Program[]>(this.API)
.pipe(
tap(console.log)
)
}
component:
import { Component, OnInit } from "@angular/core";
import { Observable } from "rxjs";
import { ProgramsService } from "./../shared/programs.service";
import { Program } from "../model/program";
@Component({
selector: "app-programs-list",
templateUrl: "./programs-list.component.html",
styleUrls: ["./programs-list.component.scss"]
})
export class ProgramsListComponent implements OnInit {
programs: Program[];
//programs$:Observable<Program>
constructor(private service: ProgramsService) {}
ngOnInit() {
this.service
.list()
.subscribe(dados => (this.service = dados));
}
}
html:
<div class="container">
<div class="row" *ngFor="let program of programs; let i = index">
<div class="col-sm" *ngFor="let programVerdadeiro of program.programs" >
<img src="https://fakeimg.pl/200/"alt="" />
<h3>{{programVerdadeiro.name}}</h3>
<h4>segunda a sexta | 20h25</h4>
</div>
</div>
</div>