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
Bash
# 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
<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
TypeScript
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 URLfindLink
find selected link form all available links
TypeScript
@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
TypeScript
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 :
TypeScript
window.localess.on(['input', 'change'], (event) => {
if (event.type === 'input' || event.type === 'change') {
console.log(event.data);
//Update your content data ...
}
});