Angular Generic Link Component
Updated: 31 January 2024
Often we want to be able to render a link element in Angular which is able to appropriately direct a user to an internal or external website link while taking advantage of the Angular router for internal linking. Below you can see an example of a component that will enable this behaviour
Component
VSCode/Tailwind Setup
If you’re using VSCode with the TailwindCSS extension, you may also be concerned that your new class properties won’t be detected, so here’s the settings you need for that:
.vscode/settings.json
References
The basic idea and structure is from this StackOverflow answer which helped to solve the issues with the other ways of attempting this that helps ensure that the component is rendered under all conditions as well as that the href attribute is not removed