Is there a way to initialize an array of type Passenger
with a number of elements equal to the value stored in the variable count
, all within the ngOnInit()
function?
Here is the definition of the Passenger
model:
export class Passenger {
constructor(
public ageCategory: string = '',
public name: string = '',
public lastName: string = '',
public Ssn: string = '',
public birtDate: NgbDate = new NgbDate(0, 0, 0),
public passportDate: NgbDate = new NgbDate(0, 0, 0),
public gender: string = '',
public passportCountry: string = ''
) { }
}
Below is the code snippet from home.component.ts
:
import { Passenger } from '../../models/passenger';
export class HomeComponent implements OnInit {
passengers: Passenger[];
count: number = 5;
constructor() { }
ngOnInit() {
}
}