python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 7, Interview Questions Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
7 Services

What Is Angular Singleton Service?

In Angular, two ways to make a singleton service -
1.      Include the service in the AppModule
2.      Declare that the service should be provided in the application root.

The preferred way to create a singleton service - Form beginning to Angular 6 is –
import { Injectable } from '@angular/core';

  providedIn: 'root',
export class CustomerService {

Another way to create a singleton service - Include service in the AppModule

customer.service.ts –
import { Injectable } from '@angular/core';

export class CustomersService {

  constructor() { }

And app.module.ts -
import {CustomerService} from './customers.service';

//AppModule class with @NgModule decorator
  //Static, this is the compiler configuration
  //declarations is used for configure the selectors.
  declarations: [
  //Composability and Grouping
  //imports used for composing NgModules together.
  imports: [
  //Runtime or injector configuration
  //providers is used for runtime injector configuration.
  providers: [CustomerService],
  //bootstrapped entry component
  bootstrap: [AppComponent]
export class AppModule { }

For more detail kindly refer the link.... 

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - and
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like Powered by Blogger.
ASK Questions