If you want to write code in ES7, I think the most concise approach to specify injections at this time is to use static getter for parameters
:
import {Component, View, DynamicComponentLoader, ElementRef } from 'angular2/angular2'
@Component({
selector: 'my-app'
})
@View({
template: '<div #container></b>'
})
export class App {
static get parameters() {
return [[DynamicComponentLoader], [ElementRef]];
}
constructor(dynamicComponentLoader, elementRef) {
dynamicComponentLoader.loadIntoLocation(DynamicComponent, elementRef, 'container');
}
}
See this plunker
If you want to write code in ES6, which doesn't support decorators, you must also use static getter for annotations
property. In this case you must import ComponentMetadata
and ViewMetadata
instead of Component
and View
For example:
import {ComponentMetadata, ViewMetadata, DynamicComponentLoader, ElementRef } from 'angular2/angular2';
export class App {
static get annotations() {
return [
new ComponentMetadata({
selector: 'app'
}),
new ViewMetadata({
template: '<div #container></b>'
})
];
}
static get parameters() {
return [[DynamicComponentLoader],[ElementRef]];
}
constructor(dynamicComponentLoader, elementRef) {
dynamicComponentLoader.loadIntoLocation(DynamicComponent, elementRef, 'container');
}
}
See this plunker
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…