Search code examples
javascriptangularweb-component

Do Angular 5 components need a `-` in the selector?


I'm reviewing this Angular 5 forms youtube tutorial and in it Sebastian initially has the form selector named app-form01, but he removes the app- portion. IIUC custom elements are supposed to have the -. Has this been relaxed?


Solution

  • You can have your tags without the - separating words, Angular won't know your words are joined, it's just another identifier for it:

    <app-my-tag> -> <appmytag>

    Furthermore, you can leave out the whole prefix altogether:

    <app-my-tag> -> <mytag>

    But, not using - separators make your tags harder to read, and not using prefixes for your custom tags increases the chances of name clashes.