How to set default value for PrimeNG p-dropdown

后端 未结 8 1098
南笙
南笙 2020-12-09 17:53

I am using PrimeNG in my angular5 app. I have issue with p-dropdown

Question

I have p-dropdown for showing countries. I bind the select opti

8条回答
  •  眼角桃花
    2020-12-09 18:47

    I use this solution to fix this

    html:

    
    

    ts:

        public country;
        public countries;
        ngOnInit() {
            this.applicant.country = 'India';
            this.getCountry().then(()=>{
              this.country = this.applicant.country
            })
        } 
        getCountry(){
          return new Promise( (resolve,reject) => {
            this.UserService.getallcountries().subscribe(result => {
              this.cnt.forEach(element => {
                this.countries.push({
                  label: element.name,
                  value: element.id
                });
              });
              resolve();
            }, error =>{
              reject();
            });
          })          
        }
        changeCountry(){
         this.country = this.applicant.country;
        }
    

    it work at primeng 6.1.3

提交回复
热议问题