0

I want to choose the Objects that I want to put in the tasks array according to IdEmployee Im trying to display the content of data (in which there is the field "IdEmployee"), but when I display it, I can see : data.IdEmployee = undefined

In the html file, I can see the entire array from my database

@Component({
  selector: 'app-display-tasks',
  templateUrl: './display-tasks.component.html',
  styleUrls: ['./display-tasks.component.css']
})
export class DisplayTasksComponent implements OnInit {

  constructor(private http:HttpClient) { }
  tasks:any=[]

  ngOnInit(): void {
    this.refreshList();
  }

  refreshList(){
    this.http.get<any>(environment.API_URL+'task')
    .subscribe(data=>{
      this.tasks=data;
      alert("data.IdEmployee = "+data.IdEmployee)
    })
  }
}
user123456
  • 171
  • 11

1 Answers1

0

You are returning an array of objects as data.

Try:

alert("data.IdEmployee = " + tasks[0].IdEmployee)

This way you are fetching the IdEmployee of the first object in your array.

If you always get back just one object, you might want to consider changing the back-end to just return an object instead of an array of objects.

(I doubt you want to iterate over an array and alert all the IdEmployee's?)

H3AR7B3A7
  • 4,366
  • 2
  • 14
  • 37