我最近在我的项目中使用了NgxSpinner,我在spinner.hide()上也遇到了这种奇怪的行为。我想让这个功能在订阅功能中实现,因为你知道吗?那是最适合的地方..。只有当API有任何响应时,旋转器才会隐藏.
我所说的例子:
this.spinner.show();
this.authService.login(this.formLogin.value).subscribe({
next: (token) => {
console.log(token);
StorageUtil.login(token.token, token.refreshToken);
},
error: (error) => this.showError(),
complete: () => {
console.log('Bateu here');
this.spinner.hide();
},
});但每次我试着这样做,旋转器就会打开,但它永远不会关闭.我知道setTimeout函数..。但那完全是胡说八道,对吧?
setTimeout(() => {
this.spinner.hide();
}, 2000);我是不是做错什么了..。
发布于 2022-06-28 23:13:53
我在我的项目中使用这个,效果很好。
ngOnInit(): void {
this.spinner.show().then();
this.coursService.getCoursOfMySchool(user.school.idSchool).subscribe(value => {
this.courses = value
this.spinner.hide().then()
});
}发布于 2022-06-29 03:02:12
只有在“authService”类中定义的“登录”方法没有返回任何可观察到的结果时,才会发生这种情况。因为没有其他理由可以解释为什么订阅的完整方法不运行。即使在与API交互时有任何错误,完整的方法也会运行。
请检查/确认以下内容:
1.您是否看到在订阅的next和complete部分中定义的控制台消息?2登录方法是否返回任何可观察到的信息?类似于下面的屏幕截图:
return this.httpClient.post('API_END_POINT_URL',requestBody,httpOptions);让我知道你会发现什么,并请提供你的反馈,并相应地提出这个答案,这样它也会帮助其他人。
https://stackoverflow.com/questions/72794038
复制相似问题