Hi,
I have trying to work this out for weeks, looking all over the Internet and I can’t seem to find a solution.
How can I print from my .json file: year name and course name? Do I have to bind career.id and year.id together so I can show that career year courses? How could I do that? Thanks in advance!
.ts file
import { Component, OnInit } from '@angular/core';
import { MenuController, NavController } from '@ionic/angular';
import { Router } from '@angular/router';
@Component({
selector: 'app-carreras',
templateUrl: './carreras.page.html',
styleUrls: ['./carreras.page.scss'],
})
export class CarrerasPage implements OnInit {
carrera: any;
constructor(
public menu: MenuController,
public router: Router,
public navContrller: NavController,
) { }
ngOnInit() {
fetch('../../../assets/data/BDs/carreras.json').then(res => res.json()).then(json => {
this.carrera = json;
});
}
}
.html file
//This works
<ion-item class="carreerSelectionButton">
<ion-label position="floating">Carrera</ion-label>
<ion-select interface="action-sheet" placeholder="Seleccione su carrera" cancel-text="Cancelar">
<ion-select-option *ngFor="let c of carrera; index as i">{{c.name}}</ion-select-option>
</ion-select>
</ion-item>
/This doesn't work
<ion-item class="yearSelectionButton">
<ion-label position="floating">Año</ion-label>
<ion-select interface="action-sheet" placeholder="Seleccione su carrera" cancel-text="Cancelar">
<ion-select-option *ngFor="let c of carrera; index as i">{{c.year.name}}</ion-select-option>
</ion-select>
</ion-item>
.json file
[{
"id": "LCC",
"name": "Licenciatura en Ciencias de la Computación",
"year": [{
"id": 1,
"name": "Primer Año",
"quarter": [{
"id": 1,
"course": [{
"id": "EA",
"name": "Elementos de Álgebra"
},
{
"id": "RPA",
"name": "Resolución de Problemas y Algoritmos"
},
{
"id": "IC",
"name": "Introducción a la Computación"
},
{
"id": "MSI",
"name": "Modelados y Sistemas de la Información"
}
]
},
{
"id": 2,
"course": [{
"id": "DDA",
"name": "Desarrollo de Algoritmos"
},
{
"id": "EAL",
"name": "Elementos de Álgebra Lineal"
},
{
"id": "ETC",
"name": "Elementos de Teoría de la Computación"
},
{
"id": "MODATOS",
"name": "Modelados de Datos"
}
]
}
]
},