reza
reza

Reputation: 6358

PrimeNg selectButton: how to display one as selected

I have an array of PrimeNg selectButtons and need to show the first one as pressed. Not finding any guidance on that. Anyone know of the API to do this?

Upvotes: 2

Views: 7201

Answers (2)

Vũ Long
Vũ Long

Reputation: 1

or if u dont, just set selectedCity = null

Upvotes: 0

Kld
Kld

Reputation: 7068

You just need to initialize the value of ngModel [(ngModel)]="selectedCity"

@Component({
  selector: 'my-app',
  template: '<p-selectButton [options]="cities" [(ngModel)]="selectedCity"></p-selectButton>'
})
export class AppComponent {

    selectedCity = 'London';

    cities: any[];

    ngOnInit() {

        this.cities = [                
            {label:'London', value:'London'},
            {label:'Istanbul', value:'Istanbul'},
            {label:'Paris', value:'Paris'}
        ]
    }
}

Upvotes: 6

Related Questions