Angular
Wink-componenten zijn zelf Angular Elements — ze integreren natuurlijk in Angular-applicaties. De enige vereiste setup is Angular’s compiler vertellen om onbekende elementnamen toe te staan.
Installeren
Section titled “Installeren”npm install @wink/elementsBootstrap — laad CDN één keer
Section titled “Bootstrap — laad CDN één keer”Roep load() aan vóór bootstrapApplication (of binnen APP_INITIALIZER):
import { bootstrapApplication } from '@angular/platform-browser';import { AppComponent } from './portal/app.component';import { load } from '@wink/elements';
load({ clientId: import.meta.env['NG_APP_WINK_CLIENT_ID'] });
bootstrapApplication(AppComponent).catch(console.error);Sta aangepaste elementnamen toe
Section titled “Sta aangepaste elementnamen toe”Voeg CUSTOM_ELEMENTS_SCHEMA toe aan elk standalone component (of module) dat <wink-*> tags rendert:
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
@Component({ selector: 'app-hotels', standalone: true, schemas: [CUSTOM_ELEMENTS_SCHEMA], template: ` <wink-content-loader layout="HOTEL" [id]="layoutId" /> <wink-lookup /> `,})export class HotelsComponent { layoutId = 'YOUR_LAYOUT_ID';}Attributen binden
Section titled “Attributen binden”De template-syntaxis van Angular werkt direct met stringattributen van custom elementen:
<!-- Statisch --><wink-content-loader layout="HOTEL" id="abc123" />
<!-- Dynamische binding --><wink-content-loader [attr.layout]="layout" [attr.id]="layoutId" />Gebruik [attr.name] binding wanneer de waarde dynamisch is — Angular’s reguliere [property] binding richt zich op DOM-eigenschappen, niet op HTML-attributen, waarop custom elementen vertrouwen.
Omgevingsvariabelen
Section titled “Omgevingsvariabelen”Voor @angular/cli 16+ projecten, gebruik environment.ts of de NG_APP_* prefix met @ngx-env/builder:
export const environment = { winkClientId: 'YOUR_CLIENT_ID',};import { environment } from './environments/environment';load({ clientId: environment.winkClientId });TypeScript-typen
Section titled “TypeScript-typen”Het @wink/elements pakket exporteert getypte interfaces voor alle componentattributen:
import type { WinkContentLoaderAttributes, WinkLayout } from '@wink/elements';
const attrs: WinkContentLoaderAttributes = { layout: 'HOTEL' as WinkLayout, id: 'abc123',};