如何解决错误 'The name of the class AccordionGroup should end with the suffix Component'
How to resolve the error 'The name of the class AccordionGroup should end with the suffix Component'
我在 angular2 中遇到错误,typescript.The class AccordionGroup 的名称应该以后缀 Component.Its 结尾,不会停止执行,但它显示 error.I 有在 angular2 中实现了手风琴,typescript.Here 是我的 code.Please 帮助我提前感谢。
import {Component, Input, OnDestroy} from '@angular/core';
@Component({
selector: 'accordion',
template:'<ng-content></ng-content>'
})
export class Accordion {
groups: Array<AccordionGroup> = [];
addGroup(group: AccordionGroup): void {
this.groups.push(group);
}
closeOthers(openGroup: AccordionGroup): void {
this.groups.forEach((group: AccordionGroup) => {
if (group !== openGroup) {
group.isOpen = false;
}
});
}
removeGroup(group: AccordionGroup): void {
const index = this.groups.indexOf(group);
if (index !== -1) {
this.groups.splice(index, 1);
}
}
}
@Component({
selector: 'accordion-group',
template: `
<div class="errors-cont" [ngClass]="{'panel-open': isOpen}">
<div class="acc-header" (click)="toggleOpen($event)">
<ng-content select="error-header"></ng-content>
</div>
<div class="acc-desc" [hidden]="!isOpen">
<ng-content select="error-body"></ng-content>
</div>
</div>
`
})
export class AccordionGroup implements OnDestroy {
private _isOpen: boolean = false;
@Input() heading: string;
@Input()
set isOpen(value: boolean) {
this._isOpen = value;
if (value) {
this.accordion.closeOthers(this);
}
}
get isOpen() {
return this._isOpen;
}
constructor(private accordion: Accordion) {
this.accordion.addGroup(this);
}
ngOnDestroy() {
this.accordion.removeGroup(this);
}
toggleOpen(event: MouseEvent): void {
event.preventDefault();
this.isOpen = !this.isOpen;
}
}
根据此处的样式指南:https://angular.io/guide/styleguide#style-02-03
Do append the symbol name with the conventional suffix (such as Component
, Directive
, Module
, Pipe
, or Service
) for a thing of that type.
因此,如果您将 AccordionGroup
组件名称更改为 AccordionGroupComponent
,问题就会得到解决。这适用于您的所有服务和组件。
.eslintrc.json
我用过这个
"rules": {
"@angular-eslint/component-class-suffix": [
"error",
{
"suffixes": [
"Page",
"Component"
]
}
]
}
我在 angular2 中遇到错误,typescript.The class AccordionGroup 的名称应该以后缀 Component.Its 结尾,不会停止执行,但它显示 error.I 有在 angular2 中实现了手风琴,typescript.Here 是我的 code.Please 帮助我提前感谢。
import {Component, Input, OnDestroy} from '@angular/core';
@Component({
selector: 'accordion',
template:'<ng-content></ng-content>'
})
export class Accordion {
groups: Array<AccordionGroup> = [];
addGroup(group: AccordionGroup): void {
this.groups.push(group);
}
closeOthers(openGroup: AccordionGroup): void {
this.groups.forEach((group: AccordionGroup) => {
if (group !== openGroup) {
group.isOpen = false;
}
});
}
removeGroup(group: AccordionGroup): void {
const index = this.groups.indexOf(group);
if (index !== -1) {
this.groups.splice(index, 1);
}
}
}
@Component({
selector: 'accordion-group',
template: `
<div class="errors-cont" [ngClass]="{'panel-open': isOpen}">
<div class="acc-header" (click)="toggleOpen($event)">
<ng-content select="error-header"></ng-content>
</div>
<div class="acc-desc" [hidden]="!isOpen">
<ng-content select="error-body"></ng-content>
</div>
</div>
`
})
export class AccordionGroup implements OnDestroy {
private _isOpen: boolean = false;
@Input() heading: string;
@Input()
set isOpen(value: boolean) {
this._isOpen = value;
if (value) {
this.accordion.closeOthers(this);
}
}
get isOpen() {
return this._isOpen;
}
constructor(private accordion: Accordion) {
this.accordion.addGroup(this);
}
ngOnDestroy() {
this.accordion.removeGroup(this);
}
toggleOpen(event: MouseEvent): void {
event.preventDefault();
this.isOpen = !this.isOpen;
}
}
根据此处的样式指南:https://angular.io/guide/styleguide#style-02-03
Do append the symbol name with the conventional suffix (such as
Component
,Directive
,Module
,Pipe
, orService
) for a thing of that type.
因此,如果您将 AccordionGroup
组件名称更改为 AccordionGroupComponent
,问题就会得到解决。这适用于您的所有服务和组件。
.eslintrc.json
我用过这个
"rules": {
"@angular-eslint/component-class-suffix": [
"error",
{
"suffixes": [
"Page",
"Component"
]
}
]
}