Auo*_*Auo 4 angular2-forms angular
我是Angular2的新手,我有一个无线电组,我正在尝试使用[(ngModel)]将它绑定到实体person.testBoolean,以便我可以将它保存在数据库中.我想设置一个默认值为选中,我看到几个例子,发现他们将默认值设置为[(ngModel)],但在我的情况下,我想将它绑定到我的实体,因此我不能使用[(ngModel)] .任何人都可以建议其他选择.checked = idx不起作用.
<div class="form-group">
<label for="radioboolean">Boolean: </label>
<div *ngFor="let entry of entries; let idx = index" class="radio-inline" >
<input type="radio" [(ngModel)]="person.testBoolean" name="radiogroup" [checked]="idx === 1" [value]="entry.id" />{{ entry.description }}
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
Ts码:
entries = [
{id: 1, description: 'True' },
{id: 2,description: 'False'},
{id: 3,description: 'Undefined'}
];
Run Code Online (Sandbox Code Playgroud)
人是我的实体:
export interface IPerson {
id: string;
name: string;
testNumber: number | null;
testDatetime: Date | null;
testBoolean: boolean | null;
// Refs to parent entities
team: ITeam;
teamId: string;
};
Run Code Online (Sandbox Code Playgroud)
你可以使用这样的条目id: [checked]="entry.id === 1"
<div *ngFor="let entry of entries; let idx = index" class="radio-inline" >
<input type="radio" [(ngModel)]="person.testBoolean" name="radiogroup" [checked]="entry.id === 1" [value]="entry.id" />{{ entry.description }}
</div>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12994 次 |
| 最近记录: |