Data fetched from api is not getting displayed on screen but i am getting the data in console .
data.service.ts
const httpOptions = {
headers:new HttpHeaders({'Content-Type':'application/json'})
};
@Injectable()
export class DataService {
constructor(private http: HttpClient) {}
getuserdetails(){
return this.http.get<any>
('http://jsonplaceholder.typicode.com/users/1')
.pipe(map(item => {
return item;
}));
}
}
information.component.ts
export class InformationComponent implements OnInit {
dataItem:any = {}
constructor(private data: DataService) {
this.data.getuserdetails().subscribe(item=>{
console.log(item);
this.dataItem=item;
});
}
ngOnInit() {
}
}
information.component.html
<div *ngIf="dataItem?.length>=0">
<div *ngFor='let x of dataItem'>
{{x.name}}
</div>
</div>
Here i am getting the details of user 1 in console but its not getting displayed on main screen.