I have to select all checkboxes if user select 'All Neighbourhoods' checkbox in angular. I tried with below code. But not working. How to fix this in angular 2?
explore-list.Component.html
<div class="checkbox_cont">
<div class="checkbox ">
<!--<input id="modal_checkbox1" type="checkbox" name="categories" unchecked="">-->
<input type="checkbox" name="allneighbourhoods" [value]="allneighbourhoods" (change)="neighbourhoodname [$event.target.getAttribute('value')]=$event.target.checked" id="allneighbourhoods" ng-click="toggleSelect($event)" />
<label for="allneighbourhoods">All Neighbourhoods</label>
</div>
</div>
<div class="modal_line"></div>
<div class="checkbox " *ngFor="let neighbourhood of neighbourhoods;let i=index;">
<input type="checkbox" name="neighbourhoodname[{{i}}]" [value]="neighbourhood" (change)="neighbourhoodname [$event.target.getAttribute('value')]=$event.target.checked" id="{{neighbourhood}}" [checked]='true' />
<label for="{{neighbourhood}}">{{neighbourhood}}</label>
</div>
explore-list.Component.ts
export class ExploreListComponent implements OnInit {
neighbourhoodname={};
toggleSelect = function(event){
this.forEach(this.checkboxes, function(item){
console.log(item);
item.selected = event.target.checked;
});
}
}
neighbourhoods json