extensions icon indicating copy to clipboard operation
extensions copied to clipboard

Button loading directive has conflict with disabled directive

Open ChrTall opened this issue 2 years ago • 4 comments

I would like to use the [loading] directive, while the api loads data, for a button. This works like described in the docs, but I have the problem that I also want to conditionally set the [disabled] directive on the button, which seems to have no effect. The button is used with the [matMenuTriggerFor] directive to display a MatMenu.

ChrTall avatar Apr 21 '23 15:04 ChrTall

Can you give an online example? I want to know how you use it.

nzbin avatar Apr 22 '23 07:04 nzbin

@nzbin Hi! Is this issue closed since it's fixed or not? I faced the same issue by combining the [disabled]="formGroup.invalid" and [loading]="isLoadingSave"

<button
            type="button"
            mat-flat-button
            [disabled]="myForm.invalid"
            [loading]="isLoadingSave"
            color="primary"
            (click)="saveForm()">
            {{ t('BUTTONS.save') }}
</button>

On saveForm, the flag isLoadingSave is set to false when an API completes and also the form is reset to its initial state. If I remove the loading attribute, the button correctly disable, but with disabled and loading together not.

Lib version used: 16.1.3

bonfantefilippo avatar Apr 04 '24 08:04 bonfantefilippo

@nzbin, we've just encountered the same issue. Looking at the source code, this issue happens because whenever the loading input flag is changed back to false, the disabled attribute is always removed, not taking into consideration that we may only want to stop the loader, but keep the button disabled.

miroslavgrozdanovski avatar Jul 01 '24 08:07 miroslavgrozdanovski

@nzbin Hi! Is this issue closed since it's fixed or not? I faced the same issue by combining the [disabled]="formGroup.invalid" and [loading]="isLoadingSave"

<button
            type="button"
            mat-flat-button
            [disabled]="myForm.invalid"
            [loading]="isLoadingSave"
            color="primary"
            (click)="saveForm()">
            {{ t('BUTTONS.save') }}
</button>

On saveForm, the flag isLoadingSave is set to false when an API completes and also the form is reset to its initial state. If I remove the loading attribute, the button correctly disable, but with disabled and loading together not.

Lib version used: 16.1.3

Can you give me an online example?

nzbin avatar Jul 26 '24 02:07 nzbin

20.2.0 has fixed.

nzbin avatar Jul 15 '25 15:07 nzbin