我有一个promise对象需要解析为另一个组件,如何实现这一点,以便在解析component-one
中的promise时,解析为component-two
的promise对象也可以解析?< / p>
@Component({
selector: 'component-one',
template: `
<h1>Title</h1>
<component-two [promisedData]="promisedData"></component-two>
`,
directives: [ComponentTwo]
})
export class ComponentOne {
promisedData: Promise<any>;
constructor () {
this.promisedData = new Promised(resolve => {
setTimeout(function(){
resolve('Test');
}, 1000);
});
}
}
&#13;
@Component({
selector: 'component-two',
template: `
<h2>
{{processedData}}
// the {{processedData}} is undefined becaused the
// resolved promise doesn't get to parse to the component-two.
</h2>
`,
inputs: ['promisedData']
})
export class ComponentTwo {
promisedData: Promise<any>;
processedData: string;
constructor () {
PromisedData.then(data => this.processedData = data);
}
}
&#13;