After extracting data from the JSON file, I encountered a typo error message stating: Type 'any[]' is not assignable to type 'typeof User'. Here is my code in app.component.ts:
import { Component, OnInit } from '@angular/core';
import { User, UserService } from './user.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
providers: [UserService]
})
export class AppComponent implements OnInit {
title = 'Users list';
usersdata:User;
constructor(private userService: UserService) { }
ngOnInit(){
this.userService.getUsers().then(users => this.usersdata = users.data);
}
}
import { Injectable } from '@angular/core';
export class User {
id: number;
name: string;
data=[];
}
export class data {
name:string;
category:string;
}
@Injectable()
export class UserService {
constructor() { }
getUsers(): Promise<User> {
return Promise.resolve(
{ id: 1, name: 'Maria','data':[{
name:'ramu',category:'c'
}]});
}
}
You can see my complete code at this URL Code URL Stackblitz
I have attached a screenshot of the typo error below. Can you please help me identify where I made a mistake?https://i.sstatic.net/c5qqn.png