2017-07-28 103 views

回答

2

你只需要初始化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'} 
     ] 
    } 
} 
+0

我有这样的线下降为我的测试,以真正了解的代码,果然我打破了部分代码:(谢谢 – reza