1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

How to set by default selected values in PrimeNg MultiSelect with Angular 4 Reactive Form?

Discussão em 'Angular' iniciado por Ketan Navadiya, Novembro 7, 2024 às 16:12.

  1. I am using MultiSelect control from PrimeNg (PrimeNg Multiselect) & Angular4 with a Reactive Form, and I want to keep some my items default selected during form loading.

    HTML

    <div class="col-md-4">
    <span translate>settings.account.webhook.label.additional.variables</span>
    <p-multiSelect [options]="sensorsList" (onChange)="changeSensorsList($event)"
    formControlName="selectedSensorsList" name="selectedSensorsList" [panelStyle]="{minWidth:'20em'}"></p-multiSelect>
    </div>


    Here is my TypeScript code

    sensorsList = [
    { label: 'lat', value: {'id': 0, 'itemName': 'lat', 'selected': false }},
    { label: 'lng', value: {'id': 1, 'itemName': 'lng' , 'selected': false}},
    { label: 'address', value: {'id': 2, 'itemName': 'address' , 'selected': false}},
    { label: 'origin', value: {'id': 3, 'itemName': 'origin' , 'selected': false}}
    ];

    this.addEditWebhookForm = this._formBuilder.group({
    name: [(_webhookToEdit) ? _webhookToEdit['name'] : '', [Validators.required]],
    selectedSensorsList: []
    });

    Continue reading...

Compartilhe esta Página