Last active
September 15, 2017 21:30
-
-
Save nomanHasan/584b291b61bbd2d49c9644898041f727 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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