我在使用以下的包版本时,尝试对当前项目进行AOT编译时遇到了问题:
- @ngtools/webpack@6.0.3
- @angular@latest (6.0.2)
- Webpack@4.0.0
这里可以找到我的webpack和tsconfig.json配置
我遇到了一些与模板中使用的private
/protected
范围以及一些不真正需要它的函数所提供的某些提取参数(例如,未在EventBinding中使用的$event)相关的问题。
现在我有了以下列表,但是我无法找到我的问题所在:
/path/to/app/header/main-header/main-header.component.html(85,7): : 指令TableOfContentComponent,期望0个参数,但实际上得到了1个。 (1,1): : 指令TableOfContentComponent,期望0个参数,但实际上得到了1个。
我的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
属性。
@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)::指令SliderComponent,期望0个参数,但实际得到了1个。 (1,1)::指令SliderComponent,期望0个参数,但实际得到了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): : 指令CarouselComponent预期有0个参数,但实际上传入了1个。 (1,1): : 指令CarouselComponent预期有0个参数,但实际上传入了1个。
这个问题和前一个非常接近,我认为问题是一样的。
/path/to/app/document/page/page.component.html(7,9): : 指令InfinityPageScrollComponent预期有0个参数,但实际上传入了1个。 (1,1): : 指令InfinityPageScrollComponent预期有0个参数,但实际上传入了1个。
在这里我们没有任何关于InfinityPageScrollComponent
的输入,而标签的调用方式是这样的:<ps-infinity-page-scroll></ps-infinity-page-scroll>
我特别说明一下,当我在我的webpack上禁用AOT时,所有的东西都能正常工作。
我尝试在AoT Do's and Don'ts中找到解决方案,但没有任何结果。
我还注意到,如果我禁用fullTemplateTypeCheck
,我会遇到大约18,000个错误,其中一些是隐含的任何类型和更奇怪的是,在构造函数中声明的服务的未定义属性。
--- EDIT 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);
}
}
HeaderItemAbstract
的代码吗? - user4676340tableOfContentService
和DeviceService
是否被装饰器@Injectable()
所修饰? - user4676340