Dependency injection 如何在AngularJS中解析和创建泛型类
有一节像下面这样的课Dependency injection 如何在AngularJS中解析和创建泛型类,dependency-injection,typescript,angular,Dependency Injection,Typescript,Angular,有一节像下面这样的课 export class SiteEventServiceType<T> { } 导出类SiteEventServiceType{ } 我需要如何使用angularjs 2为上述类创建实例 已尝试但不起作用: Injector.resolveAndCreate([SiteEventServiceType<string>]).get(SiteEventServiceType<string>); Injector.resolveAnd
export class SiteEventServiceType<T> {
}
导出类SiteEventServiceType{
}
我需要如何使用angularjs 2为上述类创建实例
已尝试但不起作用:
Injector.resolveAndCreate([SiteEventServiceType<string>]).get(SiteEventServiceType<string>);
Injector.resolveAndCreate([SiteEventServiceType]).get(SiteEventServiceType);
这个例子很久以前在
@组件(
选择器:“我的组件”,
//现在,供应商:
注射剂:常量[
常量绑定(
常量TypeLiteral,
toFactory:MyComponent.streamFactory)
]
)
@看法(
指令:const[MyChildComponent],
模板:“”
)
类MyComponent{
静态streamFactory()=>新的Stream.fromIterable(['Hello']);
}
@组成部分(
选择器:“我的子组件”
)
@看法(
模板:“{lastValue}}”
)
类MyChildComponent{
字符串值;
MyChildComponent(流stringStream){
stringStream.listen((值)=>lastValue=value);
}
}
另见
- c
- 还有一个悬而未决的问题
@组件(
选择器:“我的组件”,
//现在,供应商:
注射剂:常量[
常量绑定(
常量TypeLiteral,
toFactory:MyComponent.streamFactory)
]
)
@看法(
指令:const[MyChildComponent],
模板:“”
)
类MyComponent{
静态streamFactory()=>新的Stream.fromIterable(['Hello']);
}
@组成部分(
选择器:“我的子组件”
)
@看法(
模板:“{lastValue}}”
)
类MyChildComponent{
字符串值;
MyChildComponent(流stringStream){
stringStream.listen((值)=>lastValue=value);
}
}
另见
- c
- 还有一个悬而未决的问题
@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);
}
}