Angular 8 Metronic绑定未更新 [英] Angular 8 Metronic binding not updating

查看:52
本文介绍了Angular 8 Metronic绑定未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Angular 8 Metronic开始了一个项目.

I started a project with Angular 8 Metronic.

我有一个带有表格的组件.我希望微调框出现在提交点击"上,而消失在API响应上.这是组件代码的一部分:

I have a component with a form. I want spinner appears on submit click and disappear on API response. Here is a part of the component code :

@Component({
	selector: 'change-password',
	templateUrl: './change-password.component.html',
	styleUrls: ['./change-password.component.scss'],
})
export class ChangePasswordComponent implements OnInit, OnDestroy {

	isLoading: boolean = false;
	...
	submit() {

		this.isLoading = true;
		
		this.utilisateurService
			.changePassword(changePasswordData).pipe(finalize(() => this.isLoading = false))
			.subscribe(() => {});
	}
        ...
}

<form class="kt-form" [formGroup]="changePasswordForm" autocomplete="off">
        ...
	<div class="kt-login__actions">
		<button (click)="submit()" 
		[ngClass]="{'kt-spinner kt-spinner--right kt-spinner--md kt-spinner--light': isLoading}">
			Submit
		</button>
	</div>
</form>

当我单击提交"按钮时, isLoading 属性将更新为 true ,并出现微调框.当执行 finalize()时, isLoading 属性将更新为 false ,但微调框不会消失...

When I click on submit button, isLoading property is updated to true and spinner appears. When finalize() executes, isLoading property is updated to false but spinner do not disappear...

我不明白.

我尝试使用NgZone,但存在相同的问题.

I tried to use NgZone but same problem.

有什么主意吗?

修改

我尝试点击并订阅.还是一样的问题.问题仅在于渲染.如果我再次单击提交按钮,则 isLoading 属性为 false ,与预期的一样.但是微调器仍在运行.

I tried with tap and subscribe. Still the same problem. Problem is only for rendering. If I click on submit button again, isLoading property is false, as expected. But spinner still running.

推荐答案

您可以在 app.component.ts 文件 changeDetection配置中将其设置为默认.

You can resolve this problem, in the app.component.ts file changeDetection configuration set to Default.

这篇关于Angular 8 Metronic绑定未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆