Angular

Angular is a popular open-source framework written in TypeScript that is primarily used for building single-page web applications (SPAs).

Library

Localess provides an Angular Library @localess/angular that should help to integrate with API and Visual Editor.

Install

# NPM
npm install @localess/angular@latest
# YARN
yarn add @localess/angular@latest
# PNPM
pnpm add @localess/angular@latest

How to Enable Visual Editor Feature

Add the script at the end of your HTML, and replace the domain name with your Firebase domain name.

<html>
  ...
  <!-- Add ad the end of your HTML -->
  <script type="text/javascript" async src="https://{{project-id}}.web.app/scripts/sync-v1.js"></script>
</html>

Client Provider

const LOCALESS_URL = 'https://my-localess.web.app';
const LOCALESS_SPACE = 'I1LoVe2LocaLess4Rever';

export const appConfig: ApplicationConfig = {
  providers: [
    provideLocalessBrowser({
      origin: LOCALESS_URL,
      spaceId: LOCALESS_SPACE,
    }),
  ],
};

Client Base Component

Extend your component with the library LocalessComponenet components.

Implement id() method to return the component's id. It will help to identify the component in the Localess VisualEditor UI.

Now you have access to two utilities :

  • assetUrl - convert asset ID to a full asset URL
  • findLink find selected link form all available links
@Component({
  selector: 'llw-schema-hero-section',
  standalone: true,
  templateUrl: 'hero-section.component.html',
  styleUrl: 'hero-section.component.scss',
  imports: []
})
export default class HeroSectionComponent extends LocalessComponent {

  data = input.required<HeroSection>();
  links = input.required<Links>();

  override id(): string {
    return this.data()._id;
  }

  // access assetUrl and findLink functions
}

Server Usage

const LOCALESS_URL = 'https://my-localess.web.app';
const LOCALESS_SPACE = 'I1LoVe2LocaLess4Rever';
const LOCALESS_TOKEN = 'Baz00KaT0KeN8S3CureLL';

const serverConfig: ApplicationConfig = {
  providers: [
    provideLocalessServer({
      origin: LOCALESS_URL,
      spaceId: LOCALESS_SPACE,
      token: LOCALESS_TOKEN
    }),
  ]
};

export const config = mergeApplicationConfig(appConfig, serverConfig);

Listen for Events

Your application can subscribe to the Localess Visual Editor Events :

window.localess.on(['input', 'change'], (event) => {
  if (event.type === 'input' || event.type === 'change') {
    console.log(event.data);
    //Update your content data ...
  }
});

© Copyright 2024 Lessify Rights Reserved. Build with Localess