跳转到内容

Angular

此内容尚不支持你的语言。

Wink components are themselves Angular Elements — they integrate naturally in Angular applications. The only setup required is telling Angular’s compiler to allow unknown element names.

Terminal window
npm install @wink/elements

Call load() before bootstrapApplication (or inside APP_INITIALIZER):

src/main.ts
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
import { load } from '@wink/elements';
load({ clientId: import.meta.env['NG_APP_WINK_CLIENT_ID'] });
bootstrapApplication(AppComponent).catch(console.error);

Add CUSTOM_ELEMENTS_SCHEMA to every standalone component (or module) that renders <wink-*> tags:

src/app/hotels/hotels.component.ts
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';
}

Angular’s template syntax works directly with custom element string attributes:

<!-- Static -->
<wink-content-loader layout="HOTEL" id="abc123" />
<!-- Dynamic binding -->
<wink-content-loader [attr.layout]="layout" [attr.id]="layoutId" />

Use [attr.name] binding when the value is dynamic — Angular’s regular [property] binding targets DOM properties, not HTML attributes, which custom elements rely on.

For @angular/cli 16+ projects, use environment.ts or the NG_APP_* prefix with @ngx-env/builder:

src/environments/environment.ts
export const environment = {
winkClientId: 'YOUR_CLIENT_ID',
};
src/main.ts
import { environment } from './environments/environment';
load({ clientId: environment.winkClientId });

The @wink/elements package exports typed interfaces for all component attributes:

import type { WinkContentLoaderAttributes, WinkLayout } from '@wink/elements';
const attrs: WinkContentLoaderAttributes = {
layout: 'HOTEL' as WinkLayout,
id: 'abc123',
};