Sets isLoading variable to true on subscription and to false on completion.
this.isLoading = true;
this.service.getData()
.pipe(finalize(() => this.isLoading = false))
.subscribe(
res => {},
err => {}
);
this.service.getData()
.pipe(handleLoading(this))
.subscribe(
res => {},
err => {}
);
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent extends BaseComponent implements OnInit {
public constructor(private service: ExampleService) { }
onInit(): void {
this.service.getData()
.pipe(handleLoading(this))
.subscribe(
res => {},
err => {}
);
}
}
<div class="container">
<lib-load-indicator *ngIf="isLoading; else myAmazingContent"></lib-load-indicator>
<ng-template #myAmazingContent>
Hello
</ng-template>
</div>