Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 139893

Initializing an array of class with certain number of elements in Angular

$
0
0

I am looking for a way to initialize an array of type Passenger which its number of elements is equal to the value of variable count. How can I do it in ngOnInit()???

This is 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 = ''
    ) { }
}

And this the content of home.component.ts:

import { Passenger } from '../../models/passenger';


export class HomeComponent implements OnInit {

  passengers: Passenger[];
  count: number = 5;


  constructor() { }

  ngOnInit() {

  }

}

Viewing all articles
Browse latest Browse all 139893

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>