1

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

1

1 Answer 1

3

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)"
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, when I edited checkbox, it works: <li *ngFor="let filter of column.filters"> <div class="checkbox"> <label><input type="checkbox" [(ngModel)]="filter.checked" (ngModelChange)="onSelectFilter(column)">{{filter.value}}</label> </div> </li>
Excellent :) It's very easy to get caught out doing little "standard html" things that angular doesn't like!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.