I have a component which displays a list of 'items' which are components created with a selector. I have a checkbox which i want, when clicked to update the 'state' of all child components.
Im really struggling to find the correct solution for doing this. Please see Plunkr for more info.
//our root app component
import {Component, EventEmitter} from 'angular2/core'
class Item {
name: boolean;
constructor(name: string) {
this.name = name;
}
}
@Component({
selector: 'my-item',
template: `
<div>
<label><input type="checkbox" [(ngModel)]="state"/> {{state}}</label>
</div>
`
})
export class MyItemComponent {
state: boolean = false;
}
@Component({
selector: 'my-app',
template: `
<div style="border: 1px solid red;">
<label><input type="checkbox" [(ngModel)]="state"/> {{state}}</label>
</div>
<div *ngFor="#item of items">
<my-item></my-item>
</div>
`,
directives: [MyItemComponent]
})
export class App {
state: boolean = true;
items: Item[] = [];
constructor() {
this.items.push(new Item("hello"));
this.items.push(new Item("test"));
}
}