NetanelBasal
4/2/2018 - 3:16 PM

test-obs-todos.component.ts

@Component({
  selector: 'app-todos',
  template: `
    <div class="loading" *ngIf="loading">Loading...</div>
    <div *ngFor="let todo of todos" class="todo">
      {{todo.id}}
    </div>
  `
})
export class TodosComponent implements OnInit {
  loading: boolean;
  todos = [];

  constructor(private todosService: TodosService) { }

  ngOnInit() {
    this.loading = true;
    this.todosService.get().subscribe(todos => {
      this.todos = todos;
      this.loading = false;
    });
  }

}