ngx-oc-component
is an small Angular extension that facilitates the inclusion of any OpenComponents in angular applications.
It was built for modern browsers using TypeScript, CSS3 and HTML5 and Angular >=5.0.0
Install ngx-oc-component
using npm:
npm i ngx-oc-component --save
The oc-client library is available inside your configured OC Registry. This can be achieved in multiple ways:
<script src="https://your-oc-registry.xyz/oc-client/client.js"></script>
or
import { Component, Renderer2, Inject, AfterViewInit } from '@angular/core';
import { DOCUMENT } from '@angular/common';
export class YourComponent implements AfterViewInit {
private registry = 'https://your-oc-registry.xyz';
constructor(private renderer: Renderer2, @Inject(DOCUMENT) private document) {}
public ngAfterViewInit(): void {
const s = this.renderer.createElement('script');
s.src = `${this.registry}/oc-client/client.js`;
this.renderer.appendChild(this.document.body, s);
}
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { OcModule } from 'ngx-oc-component';
@NgModule({
imports: [BrowserModule, OcModule],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {}
import {OcOptions} from 'ngx-oc-component';
public ocOptions: OcOptions = {
baseUrl: 'yourBaseRegistryUrl',
name: 'yourComponentName',
version: 'yourComponentVersion',
parameters: yourAdditionalParameters
};
where parameters: any
.
Also, define a public method for rendered
event
public onRendered(e: any) {
const event = e.event;
const data = e.data;
/* your code */
}
<ngx-oc-component [options]="ocOptions" (rendered)="onRendered($event)"> </ngx-oc-component>