有一个类如下,
export class SiteEventServiceType<T> {
}
我如何使用angularjs 2 Injector为上述类创建实例。
试过但不行:
Injector.resolveAndCreate([SiteEventServiceType<string>]).get(SiteEventServiceType<string>);
答案 0 :(得分:0)
这个例子在https://github.com/angular/angular/pull/1779
发布了很长一段时间@Component(
selector: 'my-component',
// now providers:
injectables: const [
const Binding(
const TypeLiteral<Stream<String>>,
toFactory: MyComponent.streamFactory)
]
)
@View(
directives: const [MyChildComponent],
template: '<my-child-component></my-child-component>'
)
class MyComponent {
static Stream<String> streamFactory() => new Stream.fromIterable(['Hello']);
}
@Component(
selector: 'my-child-component'
)
@View(
template: '{{lastValue}}'
)
class MyChildComponent {
String lastValue;
MyChildComponent(Stream<String> stringStream) {
stringStream.listen((value) => lastValue = value);
}
}
另见