【问题标题】:PrimeNg selectButton: how to display one as selectedPrimeNg selectButton:如何将一个显示为选中状态
【发布时间】:2017-07-29 08:01:44
【问题描述】:

我有一个 PrimeNg 选择按钮数组,需要将第一个显示为按下状态。 没有找到任何指导。 有人知道执行此操作的 API 吗?

【问题讨论】:

    标签: angular primeng


    【解决方案1】:

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

    【讨论】:

    • 我在测试过程中删除了该行以真正理解代码,果然我破坏了代码:(谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-22
    • 2016-06-29
    • 1970-01-01
    • 2018-12-25
    • 1970-01-01
    • 2020-03-08
    • 1970-01-01
    相关资源
    最近更新 更多