What is dependency injection in Angular?

Imgur

What is dependency injection in Angular?

Angular is a standard web framework for developing SPA(Single Page Application) and Native application using javascript and HTML.

Dependency Injection is one of the core building blocks of Angular framework for developing loosely coupled application.

Dependency Injection is design pattern for developing loosely coupled application.

Dependices injection is a technique whereby one object supplies the dependency of another object.

There are several types of injection technique in software programming.

  • Constructor Injection

  • Property Injection

  • Method Injection

In Angular, we used Constructor Injection technique for injecting the dependent object in the service/component.

import { Component, ElementRef, OnInit, NgZone, EventEmitter } from '@angular/core';


@Component({
  selector: 'app-root',
  template: `
<h1>Hello World</h1>
 
 `,
  styles: []
})
export class AppComponent {

   constructor(private service: SomeService) {

  }
  
  }
  
  

إرسال تعليق

Please do not post any spam link in the comment box😊

أحدث أقدم

Blog ads

CodeGuru