2

I'd like to create a ion-select menu with ionic4 where the user can select a value from 20 to 220 but without writing manually 20, 21, 22 etc...

I've tried implementing the method of this post Tersest way to create an array of integers from 1..20 in JavaScript

But I don't know how to convert this javascript code into my ionic4 app using typescript...

Thank you for your help.

Kalamarico
  • 5,466
  • 22
  • 53
  • 70
Tom
  • 49
  • 6
  • 2
    Please show us how far you've gotten. On this site, it's the norm for question askers to put in a good effort. – Ann Kilzer Sep 29 '19 at 15:34

1 Answers1

0

What you can do is

  • First, create an array which is going to contain the numbers

    numbers = [];
    
  • Then in your ngOnInit function create a for loop to add the numbers

    ngOnInit() {
      for (let i = 20; i <= 220; i++) {
         this.numbers.push(i);
      }
    }
    
  • then use the array in your HTML file like below

    <ion-select>
        <ion-select-option *ngFor="let num of numbers">{{num}}</ion-select-option>
    </ion-select>
    

If you could share your existing codebase where you want this feature to be implemented i can show you specifically where to add the codes!

Thivagar
  • 590
  • 6
  • 13