Loading…

How can you create singleton service in angular 2?

Here is the steps to create a singleton service-
  • Import the injectable member using import {Injectable} from '@angular/core';
  • Import the HttpModule, Http and Response members’ as import { HttpModule, Http, Response } from '@angular/http';
  • Add the decorator @Injectable()
  • Export –
    export class UserService {
       constructor(private _http: Http) { }
    }

Suggest An Answer

No suggestions avaliable!

Latest post from Angular 2 Interview Questions

Ask Question