I am coding an API with Angular2
and NodeJS
, I am implementing services for my API, which should get a list of tasks and display it. Here is the task service:
import {Injectable} from '@angular/core'; import {Http, Headers} from '@angular/http'; import 'rxjs/add/operator/map'; @Injectable() export class TaskService{ constructor(private http:Http){ console.log('Task Service Initialized...'); } getTasks(){ return this.http.get('http://localhost:3000/api/tasks') .map(res => res.json()); } }
For my getTask
function (correct me if I am wrong) the .map()
function accepts my response and formats it in an array of values. Here are the task components that use the task service:
import { Component } from '@angular/core'; import {TaskService} from '../../services/task.service'; @Component({ moduleId: module.id, selector: 'tasks', templateUrl: 'tasks.component.html', }) export class TasksComponent { constructor(private taskService:TaskService){ this.taskService.getTasks() .subscribe(tasks =>{ console.log(tasks); }) } }
I would like to understand what this .subscribe()
function .subscribe()
, and I cannot find the relevant information.
source share