Angular - 声纳 - 构造函数的参数太多 (8)。允许的最大值为 7
Angular - Sonar - Constructor has too many parameters (8). Maximum allowed is 7
我的 angular 应用程序在通过思想声纳扫描时显示以上错误消息。有什么办法可以解决吗
我想传递 8 或 9 依赖项,但 sonar lint 不允许。有没有其他方法可以实现?
您可以在组件中使用动态服务注入。在那种情况下,它将有一个参数,您可以根据需要注入任意数量的服务。
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);
}
}
我的 angular 应用程序在通过思想声纳扫描时显示以上错误消息。有什么办法可以解决吗
我想传递 8 或 9 依赖项,但 sonar lint 不允许。有没有其他方法可以实现?
您可以在组件中使用动态服务注入。在那种情况下,它将有一个参数,您可以根据需要注入任意数量的服务。
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);
}
}