Angular-Sonar-Constructor参数太多(8)。允许的最大值为7
我的 angular 应用程序在通过思想声纳扫描时显示上述错误消息。有什么办法可以修复它。
我想传递 8 或 9 个依赖项,但声纳 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);
}
}
THE END
二维码