I'm submitting a ... (check one with "x")
[X] bug report => search github for a similar issue or PR before submitting
Current behavior
Angular 5.2 introduces a new AoT compiler option to perform a more thorough type check on templates. It is expected that this option will default to true in a future version:
https://blog.angular.io/angular-5-2-now-available-312d1099bd81
Building a project with angular-tree-component shows one type error:
node_modules/angular-tree-component/dist/components/tree.component.d.ts.TreeComponent.html(2,5): : Directive TreeViewportComponent, Expected 0 arguments, but got 1.
angular-tree-component version: 7.1.0
Angular version: 5.2.0
Browser: [all ]
Language: [TypeScript 2.5.2]
The error may be wrong, instead of expecting zero arguments in the class TreeViewportComponent it is possible that some function of this class expects arguments and got zero.
You can see it there:
https://stackoverflow.com/questions/48163344/angular-aot-error-in-ng-component-html-file-expected-0-arguments-but-got-1/49282073#49282073
I get the same error with ng build --prod on the latest 7.0.2 release with "fullTemplateTypeCheck": true in my project tsconfig.app.json .
ERROR in node_modules/angular-tree-component/dist/components/tree.component.d.ts.TreeComponent.html(2,5): : Directive TreeViewportComponent, Expected 0 arguments, but got 1.
(1,1): : Directive TreeViewportComponent, Expected 0 arguments, but got 1.
I found the culprit but I'm not positive of what the best fix could be. It looks like it's a result of the of the HostListener attribute on the onScroll method in tree-viewport.component.ts injecting an $event argument at runtime. With a little digging, it looks like methods with this attribute no longer throw compile time errors when fullTemplateTypeCheck is enabled. In the case of a third-party package however, the method in the compiled tree-viewport.component.d.ts appears to be throwing the error when the argument is supplied.
My workaround was to fork this project and add a parameter _$event?: any_ so it won't complain when 0 or 1 arguments are provided. I don't know if this is the best solution for now or even a good one, but I wanted to give you guys a place to start looking.
Although now that I write this I finally see that achimha had already found the source of the problem and I just don't know how to read. ^__^
Does it look like this ?
`@HostListener("onScroll", ["$event"]) someFunction(event) {
}`
I had issues with HostListener as I say in my previous comment, it was due to forgetting the argument _event_ in someFunction. The link I provided talked about it, unfortunately it doesn't work anymore.
Hope this could help.
Would be great to get this in. Last lib in my project which doesn't support this!
Same issue for me. Is there any solution to this yet ? Is there any workaround other than setting fullTemplateTypeCheck to false
Anyone found a solution for this?
7.2.0 has the same error
I can confirm that @achimha's fix eliminates the AoT compile error with fullTemplateTypeCheck: true with [email protected] in an Angular 6.0.3 project.
@achimha, are you planning to submit a PR?
I have created a PR a long time ago... https://github.com/500tech/angular-tree-component/pull/537
The maintainer needs to apply it.
Published in 7.2.1
Most helpful comment
Published in 7.2.1