I am creating an Ionic/Angular application and I want to display values from a list inside a statement using *ngFor. But for some reason *ngFor does nothing.
*ngFor does not run when I say *ngFor="let i of eventList" but does run when I place the values the variable has inside
*ngFor="let i of {'id': 1, 'name':'Superman'},{'id' :2,'name':'Batman'},
{'id' : 5, 'name':'BatGirl'},
{'id' : 3, 'name':'Robin'},
{'id' : 4, 'name':'Flash'}
];"
then it runs.
Here is my tab1.module.ts and html
import { RouterModule } from '@angular/router';
import { NgModule, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { Tab1Page } from './tab1.page';
import { AuthService} from '../auth.service';
import { HttpClientModule } from '@angular/common/http';
@NgModule({
imports: [
IonicModule,
CommonModule,
FormsModule,
HttpClientModule,
RouterModule.forChild([{ path: '', component: Tab1Page }])
],
declarations: [Tab1Page]
})
export class Tab1PageModule
{
public eventList: {'id': number, 'name': string}[] =[{'id': 1, 'name':'Superman'},
{'id' : 2, 'name':'Batman'},
{'id' : 5, 'name':'BatGirl'},
{'id' : 3, 'name':'Robin'},
{'id' : 4, 'name':'Flash'}
];
public message: any = '';
constructor(public auth: AuthService)
{
}
}
The html
<ion-item >
<ion-input type="number" clearInput></ion-input>
<ion-select placeholder="Select One" >
<ion-select-option *ngFor="let i of eventList" value="{{i.id}}">
{{i.name}}
</ion-select-option>
</ion-select>
</ion-item>
When I run this the select box stays empty. I have tried many different ways and formatting for the variable as well and it just does nothing.