Reputation: 327
I want to show a spinner when log in is processed.
constructor(public spinner: SpinnerComponent) { }
ngOnInit() {
this.spinner.showSpinner = false;
}
login() {
this.spinner.showSpinner = true;
this.userService.login(this.username, this.password).subscribe(loginResponse => {
...
this.spinner.showSpinner = false;
});
}
export class SpinnerComponent {
@Input()
showSpinner;
constructor() { }
}
<div *ngIf="showSpinner">
<mat-spinner [mode]="indeterminate"></mat-spinner>
</div>
It seems that communication between login component and spinner component to set the showSpinner value is not correct.
Any idea about how to show the spinner?
Upvotes: 1
Views: 3205
Reputation: 1286
login.component.ts
isWaiting: boolean = false;
constructor() {
}
ngOnInit() {
}
login() {
this.isWaiting = true;
this.userService.login(this.username,
this.password).subscribe(loginResponse => {
...
this.isWaiting = false;
});
}
in html
<mat-spinner *ngIf="isWaiting" [mode]="'indeterminate'">
</mat-spinner>
Upvotes: 0
Reputation: 24472
You just add spinner component to login html like this
login.component.html
<app-spinner [showSpinner]="showSpinner"></app-spinner>
login.component.ts:
public showSpinner:bollean=false;
ngOnInit() {
this.showSpinner = false;
}
login() {
this.showSpinner = true;
this.userService.login(this.username, this.password).subscribe(loginResponse => {
...
this.showSpinner = false;
});
}
Upvotes: 1
Reputation: 4145
Don't use the @Input() with showSpinner property
just create showspinner as boolean like,
showSpinner: boolean;
@Input() decorator means you are passing value by component decorator
Upvotes: 0