我有一个对象数组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];
test12
值为25.我在父组件中设置testTypeMasterData
。
ngOnInit(): void {
this._commonService.getTestTypeMasterData().subscribe((result) => {
this.testTypeMasterData = result;
});
答案 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...