import {
Component,
ContentChild,
Input,
QueryList,
ViewChildren
} from '@angular/core';
@Component({
selector: 'content-child',
template: `
Active
`
})
export class ContentChildComponent {
active = false;
activate() {
this.active = !this.active;
}
}
////////////////////
// #docregion content
@Component({
selector: 'view-child',
template: `
{{hero.name}}
`,
styles: ['.active {font-weight: bold; background-color: skyblue;}']
})
export class ViewChildComponent {
@Input() hero: any;
active = false;
@ContentChild(ContentChildComponent) content: ContentChildComponent;
activate() {
this.active = !this.active;
this.content.activate();
}
}
// #enddocregion content
////////////////////
// #docregion view
@Component({
selector: 'hero-queries',
template: `
`
})
export class HeroQueriesComponent {
active = false;
heroData = [
{id: 1, name: 'Windstorm'},
{id: 2, name: 'LaughingGas'}
];
@ViewChildren(ViewChildComponent) views: QueryList;
activate() {
this.active = !this.active;
this.views.forEach(
view => view.activate()
);
}
// #docregion defined-property
get buttonLabel() {
return this.active ? 'Deactivate' : 'Activate';
}
// #enddocregion defined-property
}
// #enddocregion view