Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spinner inside the button in Angular

Tags:

angular

I have a button Update.After entering the Inputs,When user enters Update,button should show Updating instead of Update.

But I need spinner inside this button before Updating.

I surfed in the net,there is a option of mat-progress-buttons.The problem is,the spinner is in the middle of the button without showing any text like Updating.

But I need a spinner before Updating.That spinner should be also inside the button.

Thanks in advance :)

like image 520
ramya chockalingam Avatar asked Feb 20 '26 03:02

ramya chockalingam


1 Answers

You can create a reusable button child component like this:

Working Demo

child.html

<button [disabled]="disabled" class="btn rounded-btn btn-primary submitBtn"  [style.pointer-events]="spin?'none':''"  id=submitBtn>
   <i class="fa fa-spinner fa-spin " *ngIf="spin"> </i>
  &nbsp; {{spin? 'Updating' : 'Update'}} &nbsp;
</button>

child.ts

@Component({
  selector: 'save-button',
  templateUrl: './save-button.component.html',
  styleUrls: ['./save-button.component.css']
})
export class SaveButtonComponent implements OnInit {

  constructor() { }
  @Input() disabled: boolean;
  @Input() spin: boolean

  ngOnInit() {
  }

}

parent.html

<save-button  (click)="onSubmit()" [spin]="spinLoader"></save-button>

parent.ts

spinLoader= false;

  onSubmit() {
    this.spinLoader = true
  }
like image 127
Adrita Sharma Avatar answered Feb 22 '26 21:02

Adrita Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!