A demonstration of how to integrate RuleCMS widgets into an Angular application using @rulecms/widget-angular and @rulecms/source-components-angular.
Experience the RuleCMS Angular widget integration without running the app locally.
RuleCMS is a visual content management system that lets you:
- Build widgets visually using a drag-and-drop composer
- Create responsive content that works across devices
- Publish instantly and get a unique published key for each widget
- Embed those widgets in any Angular app with a few lines of code
- Design — Log into rulecms.com and compose a widget.
- Publish — RuleCMS generates a published key (
{environmentId}---widget-…). - Authenticate — Create an app token in project settings so your app can fetch published widgets.
- Integrate — Install the Angular packages, wrap the app with
rulecms-widget-provider, and renderrulecms-widget.
@rulecms/widget-angular fetches and lays out the widget. It does not ship UI cards. You register @rulecms/source-components-angular as the default component library so text, images, buttons, and the rest of the default set can render.
git clone <repository-url>
cd use_rulecms_example_angular_project
npm install
npm startThe app is at http://localhost:4200. Demo credentials in src/app/rulecms-config.ts are enough to render the widget without extra setup. Or skip local setup and use the live demo.
npm install @rulecms/widget-angular @rulecms/source-components-angularPeer dependencies: @angular/core and @angular/common >= 17.
import { Component } from '@angular/core';
import {
RuleCMSWidgetComponent,
RuleCMSWidgetProviderComponent,
} from '@rulecms/widget-angular';
import * as sourceComponents from '@rulecms/source-components-angular';
@Component({
standalone: true,
imports: [RuleCMSWidgetProviderComponent, RuleCMSWidgetComponent],
template: `
<rulecms-widget-provider [token]="token" [libraries]="libraries">
<rulecms-widget [publishedKey]="publishedKey" />
</rulecms-widget-provider>
`,
})
export class AppComponent {
token = 'your-app-token';
publishedKey = 'your-published-key';
libraries = { default: sourceComponents };
}App token
- Log into rulecms.com
- Open project settings → API / app tokens
- Generate a token with widget access
Published key
- Create or edit a widget in the composer
- Click Publish
- Copy the generated published key
npm startDemo values live in src/app/rulecms-config.ts (same widget and token as the React examples):
DEMO_RULECMS_TOKEN— app token used to fetch the widgetDEMO_PUBLISHED_KEY— published key for the demo widget
Replace those constants with your own token and published key when you wire this up to your project.
| Piece | Role |
|---|---|
rulecms-widget-provider |
Supplies token, optional endpoint, and library registrations to widgets below it |
rulecms-widget |
Fetches a published widget and renders its layout tree |
Provider inputs
token(required): app token from RuleCMS project settingsendpoint(optional): API origin override. Leave unset so published tokens hit widget-cache anddev.tokens hit rulecms.comlibraries(required for default cards):{ default: sourceComponents }
Widget inputs
publishedKey(required):{environmentId}---widget-…for staging/productiontoken/endpoint/libraries: optional overrides if you are not using the providermode:'client-fetch'(default) or'pre-fetched'componentProps: extra host props for a component instance, keyed by column id (r-buttonreadsonClick)
The default card library: r-text, cloudinary-advanced-image, r-video, r-icon, r-button, r-divider, r-embed, r-list, r-accordion. Register it on the provider. The widget package never imports this library itself.
<rulecms-widget-provider [token]="token" [libraries]="libraries">
<header>
<rulecms-widget [publishedKey]="headerKey" />
</header>
<main>
<rulecms-widget [publishedKey]="mainKey" />
</main>
</rulecms-widget-provider>Fetch on the server (or at build time), then render without a client refetch:
import { fetchRuleCMSWidget } from '@rulecms/widget-angular';
const data = await fetchRuleCMSWidget({
publishedKey: 'your-published-key',
token: 'your-app-token',
});<rulecms-widget
mode="pre-fetched"
[publishedKey]="publishedKey"
[initialData]="data"
[libraries]="libraries"
/>This demo uses client-fetch so npm start is enough.
Pass a click handler (or any extra prop) to one component instance by column id:
<rulecms-widget
[publishedKey]="publishedKey"
[componentProps]="componentProps"
/>componentProps = {
'b721c4e2-…': { onClick: (event: Event) => console.log('cta', event) },
};Widget not displaying
- Confirm the published key and token in
src/app/rulecms-config.ts - Confirm
rulecms-widget-providerwrapsrulecms-widget - Confirm
{ default: sourceComponents }is registered - Check the browser console
Missing cards / blank layout
@rulecms/widget-angularwill not render default cards unless@rulecms/source-components-angularis registered
| Command | What it does |
|---|---|
npm start |
Dev server at http://localhost:4200 |
npm run build |
Production build in dist/ |
npm test |
Unit tests |
use_rulecms_example_angular_project/
├── src/
│ ├── app/
│ │ ├── app.component.ts # Provider + widget
│ │ ├── app.component.html
│ │ ├── app.component.css
│ │ ├── app.config.ts
│ │ └── rulecms-config.ts # Demo token and published key
│ ├── index.html
│ ├── main.ts
│ └── styles.css
├── package.json
├── vercel.json
└── README.md
- RuleCMS: rulecms.com
@rulecms/widget-angular@rulecms/source-components-angular- Angular: angular.dev
MIT