2016-01-21 30 views

回答

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); 
    } 
} 

參見