Skip to content

Instantly share code, notes, and snippets.

@nomanHasan
Last active September 15, 2017 21:30
Show Gist options
  • Select an option

  • Save nomanHasan/584b291b61bbd2d49c9644898041f727 to your computer and use it in GitHub Desktop.

Select an option

Save nomanHasan/584b291b61bbd2d49c9644898041f727 to your computer and use it in GitHub Desktop.
import { Response } from '@angular/http';
import { TodoService } from './services/todo.service';
import ToDo from './models/todo.model';
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
constructor(
//Private todoservice will be injected into the component by Angular Dependency Injector
private todoService: TodoService
) { }
//Declaring the new todo Object and initilizing it
public newTodo: ToDo = new ToDo()
//An Empty list for the visible todo list
todosList: ToDo[];
ngOnInit(): void {
//At component initialization the
this.todoService.getToDos()
.subscribe(todos => {
//assign the todolist property to the proper http response
this.todosList = todos
console.log(todos)
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment