search

Home  >  Q&A  >  body text

angular.js - angular2 encapsulating radio not working

Parent component call

<x-radio [(M)]="sex" value="male">男</x-radio>
<x-radio [(M)]="sex" value="female">女</x-radio>

Subcomponent

<input type="radio" [ngModel]="M" (ngModelChange)="MChange.emit(value)" [attr.value]="value">

Writing like this now doesn’t work at all. If you don’t use subcomponents, there is no problem, but you need to encapsulate the style of the control. Please help - -

There is no problem with data changes in this writing method, but the selection effect will not be achieved.

黄舟黄舟2794 days ago592

reply all(1)I'll reply

  • PHPz

    PHPz2017-05-15 17:10:09

    Solved, around the corner.

    <input (change)="MChange.emit(value)" [attr.value]="value" [attr.checked]="M === value">

    reply
    0
  • Cancelreply