Giter Site home page Giter Site logo

angular-services's Introduction

Services and Dependency injection

Few Important concents in angular Services Angular Services and Dependency injection

Services

Services are the class. which contains common functions, repetative Logics

Dependency Injection

Its a Mechanism to connect components to Service

useClass

Its a way to provide service to Module. It will create the new Instance

providers: [ { provide: PeopleService, useClass: PeopleService } ]

useExisting

Its a way to update old service wIth newService in Module. It will overwrIte old service

providers: [ InventorsService, { provide: PeopleService, useExisting: InventorsService } ]

useValue

Its a way to pass the object as service in Module.

const simpleEmployee = { getPeople() { return new EmployeeService().getPeople(); } };

providers: [ { provide: EmployeeService, useValue: simpleEmployee }, ]

useFactory

Its a way to pass the value to the service in Module.

const value = new EmployeeService(); const simpleReturn = () => { return value.getPeople(); };

providers: [ { provide: ManService, useFactory: simpleReturn } ]

@SkipSelf()

It will skip dependency check in component level

constructor( @SkipSelf() private inventorService:InventorService) { this.inventor = this.inventorService.getPeople() }

@Host(),

It will check dependency in component level

constructor( @Host() private inventorService:InventorService) { this.inventor = this.inventorService.getPeople() }

@Optional()

It will check dependency, if not available then It will provide null value

constructor( @Optional() private inventorService:InventorService) { this.inventor = this.inventorService.getPeople() }

angular-services's People

Contributors

arunpraba avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.