Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular - Sonar - Constructor has too many parameters (8). Maximum allowed is 7

enter image description here

My angular app showing above error message when it pass thought sonar scan. Is there any way to fixed it.

I want to pass 8 or 9 dependency but sonar lint not allowing. Is there any alternate way to make it possible?

like image 556
Vaibhav Gaikwad Avatar asked Apr 14 '21 11:04

Vaibhav Gaikwad


1 Answers

You can use dynamic service injection in the component. In that case it will have one parameter and you can inject as many service as you want.

import { Component, Injector } from '@angular/core';
import { MyService } from './my.service';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  {
  name = 'Angular';
  myService : MyService;

  constructor(private injector : Injector){
      this.myService = injector.get<MyService>(MyService);
 }
}
like image 51
Abhinav Kumar Avatar answered Nov 09 '22 10:11

Abhinav Kumar