如何为Angular 4中的单选按钮赋值

时间:2017-09-15 06:57:41

标签: json angular angular-ui

如何将JSON值分配给下面的单选按钮(无限制,自定义)。 ? 我添加了[(ngModel)]="user.accessSchedule.fullAccess"它。但它没有用。

<ol-radio-group [selected]="unlimitedAccessSchedule" id="accessSchedule"  [(ngModel)]="user.accessSchedule.fullAccess"  name="accessSchedule" orientation="horizontal">
   <ol-radio #unlimitedAccessSchedule value="true" id="unlimitedAccessSchedule" class="col-sm-4">
       Unlimited
   </ol-radio>
   <ol-radio #customAccessSchedule value="false" id="customAccessSchedule" class="col-sm-4 with-subform">
       Custom
   </ol-radio>
</ol-radio-group>

以下是JSON

"user": {
   "accessSchedule": {
     "fullAccess": true,
     "accessSchedule": [],
     "holdDateRange": null,
     "userAccessScheduleVersion": null
  }
 }

1 个答案:

答案 0 :(得分:0)

在使用单选按钮真或假选择的普通html代码中:

<input type="radio" name="fullAccess" [(ngModel)]="user.accessSchedule.fullAccess" [value]="true">

<input type="radio" name="fullAccess" [(ngModel)]="user.accessSchedule.fullAccess" [value]="false">


"user": {
   "accessSchedule": {
     "fullAccess": true,
     "accessSchedule": [],
     "holdDateRange": null,
     "userAccessScheduleVersion": null
  }
 }