【发布时间】:2018-01-08 23:43:37
【问题描述】:
考虑一下plunker
HTML
<chart [options]="options"
(load)="saveGraphInstance($event.context)"></chart>
<div (click)="switchGraph()">switch</div>
<div (click)="showLoadingForce()">show loading</div>
打字稿
class AppComponent {
constructor() {
this.options = {
title : { text : 'simple chart' },
series: [{
data: [29.9, 71.5, 106.4, 129],
}],
lang:{
loading: 'your text here',
},
};
}
options: Object;
graph: any;
switchGraph() {
this.options = {
title : { text : 'different chart' },
series: [{
data: [129.9, 171.5, 106.4, 129],
}],
lang:{
loading: 'your text here',
},
};
this.graph.showLoading() // This doesn't work
setTimeout(function() {
this.graph.showLoading() // This also doesn't work
}, 4000);
}
showLoadingForce() {
this.graph.showLoading() // User clicked work
}
saveGraphInstance(graph) {
this.graph = graph;
//this.graph.showLoading() // after loading work
}
}
我们从上面的代码中看到,在选项改变的同一个函数中,show loading 即使我设置超时时间超过 4 秒也不起作用
但如果它在load 触发器或用户启动之后完成,那么它总是有效。
这很有趣,所以我的问题如下
如果我点击
switchdiv 并立即点击show loadingdiv,加载文本将显示,然后setimeout将执行(因为4 秒延迟),但只有setimeout会遇到错误ERROR TypeError: Cannot read property 'showLoading' of undefined。这怎么可能?如果showLoadingForce成功,则意味着saveGraphInstance一定发生了(load)何时执行和解析?在githubsource code找不到相关信息
【问题讨论】:
标签: javascript angular typescript highcharts angular5