2016-03-16 12:01:33 -04:00
|
|
|
(function(app) {
|
|
|
|
|
|
|
|
var ActiveLabelComponent = ng.core.Component({
|
|
|
|
selector: 'active-label',
|
|
|
|
template: '<span class="active-label"' +
|
|
|
|
'*ngIf="active">' +
|
|
|
|
'Active' +
|
|
|
|
'</span>'
|
|
|
|
}).Class({
|
2016-08-09 12:38:25 -04:00
|
|
|
constructor: [function() { }],
|
2016-03-16 12:01:33 -04:00
|
|
|
activate: function() {
|
|
|
|
this.active = true;
|
|
|
|
}
|
|
|
|
});
|
2016-04-27 14:28:22 -04:00
|
|
|
|
2016-03-16 12:01:33 -04:00
|
|
|
// #docregion content
|
|
|
|
var HeroComponent = ng.core.Component({
|
2016-06-12 18:41:33 -04:00
|
|
|
selector: 'a-hero',
|
2016-03-16 12:01:33 -04:00
|
|
|
template: '<h2 [class.active]=active>' +
|
|
|
|
'{{hero.name}} ' +
|
|
|
|
'<ng-content></ng-content>' +
|
|
|
|
'</h2>',
|
|
|
|
inputs: ['hero'],
|
|
|
|
queries: {
|
|
|
|
label: new ng.core.ContentChild(
|
|
|
|
ActiveLabelComponent)
|
|
|
|
}
|
|
|
|
}).Class({
|
2016-08-09 12:38:25 -04:00
|
|
|
constructor: [function() { }],
|
2016-03-16 12:01:33 -04:00
|
|
|
activate: function() {
|
|
|
|
this.active = true;
|
|
|
|
this.label.activate();
|
|
|
|
}
|
|
|
|
});
|
2016-08-09 12:38:25 -04:00
|
|
|
app.HeroQueriesComponent = HeroComponent;
|
2016-03-16 12:01:33 -04:00
|
|
|
// #enddocregion content
|
|
|
|
|
|
|
|
// #docregion view
|
|
|
|
var AppComponent = ng.core.Component({
|
|
|
|
selector: 'heroes-queries',
|
|
|
|
template:
|
2016-06-12 18:41:33 -04:00
|
|
|
'<a-hero *ngFor="let hero of heroData"' +
|
2016-03-16 12:01:33 -04:00
|
|
|
'[hero]="hero">' +
|
|
|
|
'<active-label></active-label>' +
|
2016-06-12 18:41:33 -04:00
|
|
|
'</a-hero>' +
|
2016-03-16 12:01:33 -04:00
|
|
|
'<button (click)="activate()">' +
|
|
|
|
'Activate' +
|
2016-08-09 12:38:25 -04:00
|
|
|
'</button>',
|
2016-03-16 12:01:33 -04:00
|
|
|
queries: {
|
|
|
|
heroCmps: new ng.core.ViewChildren(
|
|
|
|
HeroComponent)
|
|
|
|
}
|
|
|
|
}).Class({
|
|
|
|
constructor: function() {
|
|
|
|
this.heroData = [
|
|
|
|
{id: 1, name: 'Windstorm'},
|
|
|
|
{id: 2, name: 'Superman'}
|
|
|
|
];
|
|
|
|
},
|
|
|
|
activate: function() {
|
|
|
|
this.heroCmps.forEach(function(cmp) {
|
|
|
|
cmp.activate();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// #enddocregion view
|
|
|
|
|
2016-08-09 12:38:25 -04:00
|
|
|
app.HeroesQueriesModule =
|
|
|
|
ng.core.NgModule({
|
|
|
|
imports: [ ng.platformBrowser.BrowserModule ],
|
|
|
|
declarations: [
|
|
|
|
AppComponent,
|
|
|
|
HeroComponent,
|
|
|
|
ActiveLabelComponent
|
|
|
|
],
|
|
|
|
bootstrap: [ AppComponent ]
|
|
|
|
})
|
|
|
|
.Class({
|
|
|
|
constructor: function() {}
|
|
|
|
});
|
2016-03-16 12:01:33 -04:00
|
|
|
|
|
|
|
})(window.app = window.app || {});
|