Create HTML Tag with Angular 5?

Asked

Viewed 256 times

0

With Angularjs I created a directive, and only imported using the tag and it was already available to use in any HTML file. I used this to centralize some visual objects that repeated themselves in various parts of the system, such as the navbar, sidebar, menus.. How do I do this using angular 5?

1 answer

1


At Angular 2+, the same behaviour can be obtained through components.

You create a component, and you import it into other components.

Estrutura de componentes

I recommend reading the Angular documentation,specifically the part about architecture

  • I read this documentation, when importing and trying to use Component, I get the following error: "Template parse errors: 'Navbarcomponent' is not a known element: 1. If 'Navbarcomponent' is an Angular Component, then Verify that it is part of this module. 2. To allow any element add 'NO_ERRORS_SCHEMA' to the '@Ngmodule.schemas' of this Component. ("[ERROR ->]<Navbarcomponent></Navbarcomponent> ")"

  • 1

    Your component A (Navbar) must be inside a module, which must be imported inside the module of component B (App)

  • 1

    I made a demo in stackblitz to be clear: https://stackblitz.com/edit/angular-tjnvgd

  • Thanks for the help and attention.. It worked.. I was wrong to put the class name as tag, actually the tag name is the "selector".

  • Arrange, if the answer has solved your question, mark the answer as correct right above.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.