My goal is to load a dropdown when a component renders. I have a service which hits a url and gets json data. Something like this
@Injectable()
export class St
Remove this assignment this.items = this.studentListService.getStudent().... You are trying to assign Subscription object to this.items.
ngOnInit() {
this.studentListService.getStudent().subscribe(
data => {this.items = data},
err => console.error(err),
() => console.log('Done Loading Student Data'));
}
Note : You can only access it once the http (asynchronous) call is completed. And when it is completed, your dropdown should automatically load those items. If you try to print it outside subscribe block, it gives you undefined.