gpt4 book ai didi

angular - AOT - Angular 6 - 指令 SomeComponent,预期 0 个参数,但得到 1 个。对于自制组件

转载 作者:太空狗 更新时间:2023-10-29 16:57:37 24 4
gpt4 key购买 nike

当我想使用以下包版本在 AOT 中编译我当前的项目时,我遇到了问题:

  • @ngtools/webpack@6.0.3
  • @angular@latest (6.0.2)
  • Webpack@4.0.0

my webpack and tsconfig.json configuration can be find here

我遇到了一些与 private 相关的问题/protected在模板上使用的范围和一些提取参数提供给一些并不真正需要它的函数(例如不在 EventBinding 上使用的 $event)。

现在我有以下列表,但我找不到我的问题在哪里:

/path/to/app/header/main-header/main-header.component.html(85,7): : Directive TableOfContentComponent, Expected 0 arguments, but got 1. (1,1): : Directive TableOfContentComponent, Expected 0 arguments, but got 1.

我的 main-header.component.html文件包含: //main-header.component.html

// main-header.component.ts
@ViewChildren('headerItems') public headerItems: QueryList<HeaderItemAbstract>;
mainMenuStates = {
hamburger: false,
bookmarks: false,
search: false,
toc: false,
medias: false,
article: false,
language: false
};

还有我的TableOfContentComponent不包含任何 @Input属性(property)。

@Component({
selector: 'ps-table-of-content-template',
templateUrl: './table-of-content.component.html',
animations: [slideUpAndDownAnimation]
})
export class TableOfContentComponent extends HeaderItemAbstract implements OnInit {

toc: TableOfContentModel[];

devices: DevicesModel;

tocContentHeight: number;
tocContentMargin: number;
menuHeight: string;


constructor(private tableOfContentService: TableOfContentService,
private deviceService: DeviceService,
private elemRef: ElementRef) {
super();
this.toc = this.tableOfContentService.tableOfContent;
}
}

/path/to/app/header/main-header/hamburger-menu/hamburger-menu.component.html(125,5): : Directive SliderComponent, Expected 0 arguments, but got 1. (1,1): : Directive SliderComponent, Expected 0 arguments, but got 1.

我的 hamburger-menu.component.html接近上面提供的代码:

<ps-slider-component [template]="slidable" [countItems]="associatedDocuments.length">
<ng-template #slidable>
<ul class="clearfix">
<li class="ps-hmt-associated-item-wrapper pull-left slider-item"
*ngFor="let document of associatedDocuments">
<a href="{{ document.link }}" target="_blank" class="btn-nostyle">
<div class="ps-hmt-image">
<img src="{{ document.images.thumbnail }}" alt="">
</div>
<p class="ps-hmt-title slider-text"
[matTooltip]="isArticleView ? null : document.title"
[matTooltipPosition]="'above'"
[matTooltipClass]="['ps-mat-tooltip', 'ps-mat-tooltip-doc']"
>
{{ document.title }}
</p>
</a>
</li>
</ul>
</ng-template>
</ps-slider-component>
// On ts side
associatedDocuments: Array<AssociatedDocumentModel>;
@ViewChild('slidable') slidable: ElementRef;

还有我的SliderComponent看起来像:

export class SliderComponent extends UnsubscribeHelper implements OnInit, OnChanges {

@Input() template: ElementRef;
@Input() countItems: number;
@Input() resetSlide ?: null;
@Input() fixedHeight?: null;
@Input() isVariableWidth?: null;
@Input() isBookmarks?: null;
@Input() hasSkeleton?: boolean = false;

/path/to/app/header/main-header/medias/dialogs/image-dialog.component.html(34,5): : Directive CarouselComponent, Expected 0 arguments, but got 1. (1,1): : Directive CarouselComponent, Expected 0 arguments, but got 1.

非常接近上一个,我认为问题是一样的。

/path/to/app/document/page/page.component.html(7,9): : Directive InfinityPageScrollComponent, Expected 0 arguments, but got 1. (1,1): : Directive InfinityPageScrollComponent, Expected 0 arguments, but got 1.

这里我们没有关于 InfinityPageScrollComponent 的任何输入标签是这样调用的 <ps-infinity-page-scroll></ps-infinity-page-scroll>

准确地说,当我在我的 webpack 上禁用 AOT 时,一切都像 charm 一样工作。

我已尝试在 AoT Do's and Don'ts 上找到解决方案没有任何结果。

我还注意到我是否禁用了 fullTemplateTypeCheck我面临大约 18 000 个错误,其中一些隐含的任何类型和更奇怪的、未定义的属性用于我在构造函数上声明的服务。

--- 编辑 1:为抽象类提供代码:UnsubscribeHelper ---

export abstract class HeaderItemAbstract extends UnsubscribeHelper implements AfterViewInit {
public toggleItem: string = 'out';
public ANIMATION_DURATION = slideUpAndDownAnimationDuration;

constructor() {
super();
}

// [Some other method]
/**
* Self animate after loading on DOM
*/
ngAfterViewInit()
{
// Wait next to to avoid error :
// ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked
setTimeout(() => {
this.toggleAnimation();
},100);
}
}

抽象类的代码UnsubscribeHelper :

export abstract class UnsubscribeHelper implements OnDestroy {

subscriptions: Subscription[] = [];

ngOnDestroy() {
this.subscriptions.forEach(sub => sub.unsubscribe());
}

addSubscription(subscription: Subscription) {
this.subscriptions.push(subscription);
}
}

最佳答案

好吧,我在这里准备了一个minimal, complete, and verifiable example

我注意到 @HostListner 缺少一个参数

问题示例如下:

@HostListener('window:resize', ['$event'])
onResize(): void {

}

只需删除 '$event' 就可以了。

总而言之,这两个选项可以正常工作:

// When you need the Event variable, you can use following syntax.
@HostListener('window:resize', ['$event'])
onResize($event: Event): void {

}

// When you do not need the Event variable, you can use following syntax.
@HostListener('window:resize')
onResize(): void {

}

感谢@trichetriche 的帮助。

关于angular - AOT - Angular 6 - 指令 SomeComponent,预期 0 个参数,但得到 1 个。对于自制组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50405930/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com