David Dahan
David Dahan

Reputation: 11162

Ionic3: Using ngModel with <ion-select> breaks page nav or display

When adding [(ngModel)]="selectedCategory" to a <ion-select> element in a page, the page does not display anymore:

As soon as I remove the [(ngModel)]="selectedCategory", everything works normally again.

There is no error in the console.

html

<form (ngSubmit)="onSubmit()" #f="ngForm" autocomplete="off">

    <ion-list no-margin>
      <ion-item no-margin no-lines>
        <ion-select style="max-width: 100%; padding-left: 0;"
                    interface="action-sheet"
                    [(ngModel)]="selectedCategory"
                    required
                    placeholder="Choisissez un sujet">
        <!-- <ion-options here> -->
        </ion-select>
      </ion-item>
    </ion-list>

</form>

typescript

@IonicPage()
@Component({
  selector: 'page-feedback',
  templateUrl: 'feedback.html',
})
export class FeedbackPage implements OnInit {
  @ViewChild('f') feedbackForm: NgForm;

  selectedRating: string;  // This uses ngModel too, but this one makes no problem!
  selectedCategory: string;

versions

Upvotes: 0

Views: 374

Answers (1)

Mustafa Lokhandwala
Mustafa Lokhandwala

Reputation: 814

You need to add name in ion-select like this

<ion-select style="max-width: 100%; padding-left: 0;"
                interface="action-sheet"
                [(ngModel)]="selectedCategory"
                required
                placeholder="Choisissez un sujet" name="selectName">

Hope this work for you

Upvotes: 1

Related Questions