#The class provided didn't contain any decorator Component

4 messages · Page 1 of 1 (latest)

crisp dagger
#

Hi, Angular return an error : I have forgotten to declare a @Component decorator in the class Article
But this class must not require a such decorator. It 's like an Entity in Symfony or a Plain old Java object.
I explained the architecture in the schema and join the code.

Thank you for your attention.

Schema : https://excalidraw.com/#json=0yIkxJucr_4UiPgBIdWEQ,HtJ8FEAWPPMCTLMncvEn7w
Code : https://jsfiddle.net/nj4wps8f/1/ ; Differents pages are under Ressources' Tag.
Stacktrace : https://textdoc.co/09lIuiR4rCmcTtDO

Excalidraw

Excalidraw is a virtual collaborative whiteboard tool that lets you easily sketch diagrams that have a hand-drawn feel to them.

raven garden
#
  @Input() articles: Article[];  

  constructor(private logger1: LoggerService, @Inject ( ARTICLE_TOKEN )public article: Article[]) {
    console.log(article);
    this.logger= new LoggerService;  
    this.articles=article;     
  }

Your articles are supposedly coming in via an Input. But then you're injecting articles and setting the value of the Input internally. Since you're doing that in the constructor, it will execute before Angular fully initializes the component -- so any value incoming from the injected token will be overwritten with the value set through the input.

I don't know if any of that is related to your error message, but it seems awkward. My suggestion is to clean this up first and see if that fixes your problem. Component constructors are primarily just for dependency injection. Use lifecycle methods such as ngOnInit for initialization. Use either the injected articles or an Input but not both.

If that does not fix it, then perhaps a StackBlitz that demonstrates the error could help others help you troubleshoot it.

crisp dagger
#

Thank you it will help me. I didn't no there was a redondancy. I thought that's first input was just a declaration.

crisp dagger
#

But if i use @Input it sends that the articles variable is not initialized. Articles are initialized in the Provider. I must do an injection with it somewhere to get the variable initialized ?