I am encountering an issue while trying to define a variable as type Employee. The error message 'Employee' only refers to a type but is being used as a value here. ts(2693) keeps appearing.
Here is my show-api.ts code:
import { Component, OnInit } from '@angular/core';
import {HttpClient} from '@angular/common/http';
interface Employee {
Id: String;
EmployeeName: String;
StartTimeUtc: String;
EndTimeUtc: String;
EntryNotes: String;
DeletedOn: String;
}
@Component({
selector: 'app-show-api',
templateUrl: './show-api.component.html',
styleUrls: ['./show-api.component.css']
})
export class ShowApiComponent implements OnInit {
li:any;
lis: any=[];
constructor(private http : HttpClient){
}
ngOnInit(): void {
this.http.get('API URL of my JSON file')
.subscribe(Response => {
if(Response){
hideLoader();
}
**employee: Employee[]=Response**;
});
function hideLoader(){
document.getElementById('loading')!.style.display = 'none';}
}}
Data retrieved from the API:
[
{"Id": "aa",
"EmployeeName": "bb",
"StartTimeUtc": "cc",
"EndTimeUtc": "dd",
"EntryNotes": "ee",
"DeletedOn": null },
{"Id": "ff",
"EmployeeName": "gg",
"StartTimeUtc": "hh",
"EndTimeUtc": "ii",
"EntryNotes": "jj",
"DeletedOn": null },
]
If the above issue cannot be resolved, kindly suggest an alternative method to fetch data from a JSON file.