Angular 4 directive error: Can't resolve all parameters for directive

孤街浪徒 提交于 2019-12-04 09:49:12

private items is missing a type parameter. Angular can't create component instances if it can't resolve all parameters to providers.
Resolving to providers only works with parameter types and @Inject(...) annotations.

If you don't want items to be injected, remove the parameter. There is no situation where you would need to create a component instance yourself to pass the parameter explicitely.

I just left my case here, because found just this question by my request.

I had annotation @HostListener and onResize method. @HostListener should be before and close to the related method. Like

@HostListener("window:resize", ["$event"])
onResize(event) {
    // some code
}

I got this error when had moved annotation before calling another method. Like

@HostListener("window:resize", ["$event"])
getSomeObjects (args:any = {}) {
    // some code
}

onResize(event) {
    // some code
}

Hope, this will be helpful for somebody!

veloz21

I had this error, in my case was because I have a service named Storage, but the compiler won't mark it as error, because javascript have a global variable named the same. So I just added:

import { Storage } from '@core/auth/token-storage.service';
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!