简体   繁体   中英

Pre select primeng dropdown

I have a value and I need to put it in the dropdown at start:

state is an object {'code':...,'description'}

and listState in array of state 

 loadValue(stateSave: Object) {//state save is the object  just saved
   this.state={'code':stateSave['code'],'description':stateSave['description']   }

and in my html is:

    <p-dropdown [options]="listState" [(ngModel)]="state"  optionLabel="description"></p-dropdown>

My problem is that if I have an old value just saved and I want to show it but the dropdown doesn't work, because at start it doesn't show anything. Anyone can help me?

In init() method, write the below code,

 this.state={'code':stateSave['codice'],'description':stateSave['description']}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM