title: Angular 7 Service Returns Undefined from restful API
body: <p>I'm trying to return a list of tasks from and Angular service that gets the data from a restful .NET API.  The API returns the proper data, but when console.log the result from the subscribed to function it is only undefined.  Please help!</p>
  
  <p>Here is the API method that is functioning correctly:
   TaskController.cs</p>
  
  <pre><code>[HttpGet, Route("")]
      public IEnumerable&lt;GetAllTasksAndInfoDto&gt; GetAll()
      {
          IEnumerable&lt;GetAllTasksAndInfoDto&gt; tasks = _taskRepository.GetAllTasksAndInfo();
          return tasks;
      }
  </code></pre>
  
  <p>I have two services on called task.service.ts and one called email-notification.service.ts.  Task is to return all the tasks in a collection. Email-Notification is to retrieve the tasks from the task service, then iterate through them to check a for a specific property value in the task data.</p>
  
  <p>Here is the method from task.service.ts:</p>
  
  <pre><code>export class TaskService {
  
  constructor(private http: HttpClient, private messageService: MessageService) {}
  
  getTasks(): Observable&lt;getAllTasksAndInfo[]&gt; {
      return this.http.get&lt;getAllTasksAndInfo[]&gt;(http://localhost:xxxxx/api/task)
          .pipe(
              tap(_=&gt;this.log('fetched tasks')),
          catchError(this.handleError&lt;getAllTasksAndInfo[]&gt;('getTasks', [])));
  }
  </code></pre>
  
  <p>I'm not sure how to check the data at this ^ point, but it's not showing an error.</p>
  
  <p>Here is the code from email-notification that is returning "Undefined":</p>
  
  <pre><code>export class EmailNotificationService{
  
  tasks: getAllTasksAndInfo[];
  
  constructor(private http: HttpClient, private messageService: MessageService, public  taskService: TaskService)
  {
      this.getTasks().subscribe(result =&gt; this.tasks = result);
  }
  getTasks(): Observable&lt;getAllTasksAndInfo[]&gt;{
       return this.taskService.getTasks();
  }
  
  this.tasks.forEach((task) =&gt; {
          console.log(`task: ${JSON.stringify(task)}`);
          }
      });
  </code></pre>
  
  <p>Here I am getting an error in the console for trying to iterate through and undefined object. </p>
  
  <p>Here is my typescript class:</p>
  
  <pre><code>export class getAllTasksAndInfo {
  taskId: number;
  stepName: string;
  officeName: string;
  csrName: string;
  taskType: string;
  daysActive: number;
  </code></pre>
  
  <p>}</p>
  
  <p>and here is my API class:</p>
  
  <pre><code>public class GetAllTasksAndInfoDto
  {
      public int taskId { get; set; }
      public string stepName { get; set; }
      public string officeName { get; set; }
  
      public string csrName { get; set; }
  
      public string taskType { get; set; }
  
      public int daysActive { get; set; }
  }
  </code></pre>
  
  <p>Any help appreciated. Thank you!</p>