I am having an issue with some html not loading when the component is loaded until the data being recieved from the api call via the service.
Here is the relevant code:
import { ApiService } from './services/api.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit, OnDestroy {
thedata;
subscription: Subscription;
constructor(private apiService: ApiService) {}
ngOnInit() {
this.getData();
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
getData() {
this.apiService.getUsers().subscribe(
(res) => {
this.thedata = [res];
},
(err) => {
console.log('There was an error: ' + err);
}
)
}
}
Then in the html file:
<div *ngFor="let data of thedata">
<!-- other elements here and below -->
{{ data.name }}
</div>
My problem is that although there are visual element to render it is not rendering until the data is loaded.
Is there a way to render the html whiles the data is still being loaded from the api ?
ngOnInit() { this.getData(); }if you want to render empty component maybe move it tongAfterViewInitServiceWorkerModule.register('ngsw-worker.js'),that should at least make your UI responsive