angular-docs-cn/public/docs/_examples/cb-ts-to-js/js/app/heroes-queries.component.js

83 lines
1.9 KiB
JavaScript
Raw Normal View History

(function(app) {
var ActiveLabelComponent = ng.core.Component({
selector: 'active-label',
template: '<span class="active-label"' +
'*ngIf="active">' +
'Active' +
'</span>'
}).Class({
constructor: [function() { }],
activate: function() {
this.active = true;
}
});
2016-04-27 14:28:22 -04:00
// #docregion content
var HeroComponent = ng.core.Component({
2016-06-12 18:41:33 -04:00
selector: 'a-hero',
template: '<h2 [class.active]=active>' +
'{{hero.name}} ' +
'<ng-content></ng-content>' +
'</h2>',
inputs: ['hero'],
queries: {
label: new ng.core.ContentChild(
ActiveLabelComponent)
}
}).Class({
constructor: [function() { }],
activate: function() {
this.active = true;
this.label.activate();
}
});
app.HeroQueriesComponent = HeroComponent;
// #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"' +
'[hero]="hero">' +
'<active-label></active-label>' +
2016-06-12 18:41:33 -04:00
'</a-hero>' +
'<button (click)="activate()">' +
'Activate' +
'</button>',
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
app.HeroesQueriesModule =
ng.core.NgModule({
imports: [ ng.platformBrowser.BrowserModule ],
declarations: [
AppComponent,
HeroComponent,
ActiveLabelComponent
],
bootstrap: [ AppComponent ]
})
.Class({
constructor: function() {}
});
})(window.app = window.app || {});