【发布时间】:2016-04-15 06:26:56
【问题描述】:
我基于Angular.io tutorial on pipes创建了一个简单的有状态管道:
@Pipe({
name: 'fetch',
pure: false
})
class FetchJsonPipe implements PipeTransform{
private fetchedValue = 'waiting';
private fetchedValue2 = 'waiting2';
transform(value:string, args:string[]):any {
setTimeout(() => {
this.fetchedValue = 'done';
this.fetchedValue2 = 'done2';
}, 3000);
return this.fetchedValue2;
}
}
@Component({ selector: 'sd-splash'
, template: 'hello ng2 {{ "5" | fetch }}'
, pipes: [FetchJsonPipe]
})
我的问题是,我立即从#transform 返回this.fetchedValue。
因为它只是一个字符串,所以它按值返回。后来,当超时
完成后,我只需将值 'done' 分配给一个属性(这也是
私人)。
Angular2 怎么知道初始结果 'waiting' 不是最终结果?如何
它知道更新后的值可以通过#fetchedValue 获得吗?
Promise 完全没有暴露,Angular2 也没有名字的信息
我存储结果的字段。
它唯一的线索是pure == false,我猜它指示它
观察实例的变化。但我不明白它是如何提供信息的
观看哪个字段。
但它有效!我也不知道为什么。
干杯
【问题讨论】:
标签: angular typescript frontend