Connecting the service with our todos component

First, we have to import todos service in todos component:

import {TodosService} from '../todos.service';

Then add the TodosService class in the component's constructor:

constructor(private todoService: TodosService) { }

Now, we will make use of the todo service to get, create, delete, and update todos.

This is what our todos component should look like:

import { Component, OnInit } from '@angular/core';import { TodosService } from '../todos.service';@Component({selector: 'app-todos',templateUrl: './todos.component.html',styleUrls: ['./todos.component.css']})export class TodosComponent implements OnInit {//define data typestodos: any = [];todo: any;action: any;name: any;isDone: boolean;constructor(private ...

Get TypeScript 2.x for Angular Developers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.