Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 radio button events

What are those events called in Angular 2 when radio button is selected or unselected.

Something like

<input type="radio" (select)="selected()" (unselect)="unselected()" /> 

So when I click one radio button in a group, it will fire selected() for the new selection and unselected() for the previous selection.

like image 506
Tuomas Toivonen Avatar asked May 31 '16 08:05

Tuomas Toivonen


2 Answers

It works,

<input type="radio" (change)="handleChange($event)" /> 

But you need code more to judge 'selected' or 'unselected'.
You may try this in your *.ts file:

  export class Comp {      private _prevSelected: any;      handleChange(evt) {       var target = evt.target;       if (target.checked) {         doSelected(target);         this._prevSelected = target;       } else {         doUnSelected(this._prevSelected)       }     }    } 
like image 92
Edmond Wang Avatar answered Oct 04 '22 12:10

Edmond Wang


It works when you assign the click event to the label, instead of the input.

like image 33
edu Avatar answered Oct 04 '22 12:10

edu