bluray
bluray

Reputation: 1953

Angular2 checkbox - uncheck event

Hello I have dropdown menu with checkboxes and I have a problem with call function when click on dropdown menu item. Here is my code:

 <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
          <li *ngFor="let filter of column.filters">
            <div class="checkbox">
              <label><input type="checkbox" value="" #checkbox [(ngModel)]="filter.checked" 
                 (ngModelChange)="onSelectFilter(column)">{{filter.value}}</label>
            </div>
          </li>
        </ul>

Function onSelectFilter() is not called when checkbox is checked (I need to call with uncheck). What event I must use when I need call method with check and uncheck? Thanks

Upvotes: 1

Views: 3489

Answers (1)

NightCabbage
NightCabbage

Reputation: 489

Take away the value="" and just set the initial model (filter.checked) to what you want it to start out as.

The value="" thing will just get in the way! :)

Also, it seems like you're using an ngFor to give you a list of checkboxes... but in the (ngModelChange), you are passing through the entire column (which has multiple checkboxes)... This may not be what you are intending to do?

eg. I think this might be more what you want?

(ngModelChange)="onSelectFilter(filter)"

Upvotes: 3

Related Questions