Angular
Step-by-step integration of the components into an Angular application.
Angular needs one schema flag to accept the tags. After that its property bindings and event bindings map onto the components directly, with no wrapper library and no event-name translation.
1. Install
Add the design tokens to the global styles:
2. Register the elements
Importing the library registers every tag. Do it once, in main.ts, before the
app bootstraps:
With server-side rendering, that import has to stay out of the server
bundle, because the elements extend HTMLElement, which the server does not
have:
3. Allow the tags
Without the schema Angular reports 'tuix-button' is not a known element.
4. Use them
[prop] sets a DOM property, so objects and arrays work as they are, and
(event) listens with the exact name, including camelCase ones:
Enums used in a template have to be exposed as a field (readonly IconName = IconName), or written as plain strings: iconright="building".
5. Forms
The elements are not form controls, so formControlName needs a
ControlValueAccessor. One small directive per element type is enough, and it
is reusable across the app:
Import the directive into the component and the element behaves like any other control:
For the checkbox and the toggle, the same directive shape applies with
(change) as the host listener and checked as the property.
6. Change detection
The events are plain DOM events, so Angular's zone picks them up and a template
bound to the updated field re-renders on its own. With OnPush and a signal or
an async pipe, nothing extra is needed either. A listener registered inside
ngZone.runOutsideAngular is the one exception: it has to re-enter the zone
with ngZone.run().
Troubleshooting
| Symptom | Cause |
|---|---|
'tuix-button' is not a known element | CUSTOM_ELEMENTS_SCHEMA is missing from the component or module |
HTMLElement is not defined on the server | The library is imported in code that runs during SSR; guard it with isPlatformBrowser |
Can't bind to 'options'… | The schema is missing; with it, unknown bindings are set as DOM properties |
The control stays empty with formControlName | No ControlValueAccessor; add the directive from step 5 |
IconName is not defined in a template | Enums must be exposed as a component field |