【发布时间】:2018-02-22 07:47:34
【问题描述】:
我正在实现一个微调器,它最初工作正常,但即使在页面加载后它也会继续旋转。
loader.service.ts
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
@Injectable()
export class LoaderService {
public status: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
display(value: boolean) {
this.status.next(value);
}
}
app.module.ts
导入 LoadService 并将其添加到 providers 数组中
app.component.html
我正在检查 showLoader 的值,看看它是真还是假,因为 true 会显示加载程序,而 false 不会。
<router-outlet>
<span *ngIf="showLoader" class="loading"></span>{{showLoader}}
</router-outlet>
app.component.ts
导入的LoaderService
export class AppComponent {
//for the spinner
showLoader: boolean;
//LoaderService is for the spinner
constructorprivate loaderService: LoaderService) { }
//for the spinner
ngOnInit() {
this.loaderService.status.subscribe((val: boolean) => {
this.showLoader = val;
});
}
}
custom.component.ts
@Component({
selector: 'app-custom',
templateUrl: './custom.component.html',
styleUrls: ['./custom.component.css']
})
export class CustomComponent implements OnInit {
//LoaderService is for the spinner
constructor(private loaderService: LoaderService) { }
ngOnInit() {
//http call starts
this.loaderService.display(true);
}
ngAfterViewInit() {
d3.json("https://...", function(data) {
createChart(data);
});
function createChart(data) {
...
dc.renderAll();
}//end of function
}//end of ngAfterView
}//end of export class
我正在展示一些 dc 图表,我希望在图表显示后停止微调。
我需要使用this.loaderService.display(false); 停止微调器,但在 dc.renderAll(); 之后立即使用它将 showLoader 的值显示为 false,因此不会出现微调器。
我们将不胜感激任何形式的帮助。谢谢。
【问题讨论】:
标签: javascript angular typescript progress-bar dc.js