Checbox未在Prime中检查

时间:2017-10-12 05:46:10

标签: angular primeng

我有一个对象数组testTypeMasterData,为每个对象创建复选框。我无法预先选中复选框。但如果它在HTML中显示值。

<div class="row" 
  *ngFor="let testType of testTypeMasterData">
    <div class="col col-md-8" *ngIf="testType.flgStdtest">
        <div class="form-group">
           <div class="col-md-8">
             <p-checkbox 
              name="testTypes" 
              value="{{testType.id}}" 
              label="{{l(testType.testType)}}" 
              [(ngModel)]="selectedtestTypes" 
              (onChange)="testTypeChanged($event)">
             </p-checkbox>
           </div>
        </div>
      </div>
   </div>
   Selected Categories: 
   <span *ngFor="let cat of selectedtestTypes" style="margin-
   right:10px">
      {{cat}} 
   </span>
</div>

 @Input() testTypeMasterData: testTypeDetailsDTO[];


ngOnInit(): void {
    this.selectedTenderTypes = [25];

enter image description here

test12值为25.我在父组件中设置testTypeMasterData

ngOnInit(): void {
    this._commonService.getTestTypeMasterData().subscribe((result) => {
        this.testTypeMasterData = result;
    });

1 个答案:

答案 0 :(得分:1)

I reproduced your example and effectively it doesn't work... But if you only change this : this.selectedTenderTypes = ['25'];, it should works fine.

The primeng doc indicate that value attribute can be any type, but it probably transforms it in a string. I guess that's why making the above modification works...