You can get your ECAL widget details by logging into your ECAL Admin and navigating to the “Displays” > “Manage Displays” page. For the required button, click the icon to get the “Button Code”. Make a note of Widget ID and API Key (see below).
Copy the 3 files below grouping them under ecal
folder, and put this folder in app src
folder where the Angular App Page can import or include it.
a. Copy the code snippet below and name it as ecal-angular.js
file.
/*
* embedEcalScripts enabled to only embed ecal once.
*/
function embedEcalScripts () {
if (!window.EcalWidget) {
!function(e,t,n,c,i,a,s){i=i||'EcalWidget',e.EcalWidgetObject=i,e[i]=e[i]||function(){(e[i].q=e[i].q||[]).push(arguments)},a=t.createElement(n),s=t.getElementsByTagName(n)[0],e[i].u=c,a.async=1,a.src=c,s.parentNode.insertBefore(a,s)}(window,document,'script', '//sync.ecal.com/button/v1/main.js' + '?t=' + Date.now());
}
}
/*
* renderSync function will reboot EcalWidget to ensure the Sync Button event is attached.
*/
function renderSync (apikey) {
embedEcalScripts();
clearTimeout(window.ecalSyncRenderTimeout);
function rebootWidgets () {
const eCalButton = document.getElementsByClassName('ecal-sync-widget-button');
if (window.EcalWidget &&
eCalButton.length > 0 &&
apikey) {
window.EcalWidget('destroy');
window.EcalWidget('boot', { apiKey: apikey });
return;
}
// if ecal cannot reboot, it is because the widget isn't available yet.
window.renderEcalSyncTO = setTimeout(rebootWidgets, 100);
}
window.ecalSyncRenderTimeout = setTimeout(rebootWidgets, 100);
}
/*
* Angular will call the render twice, thus it needs to be debounced.
*/
function renderEcalSyncButton (apikey) {
if (window.renderSyncCallTO) {
clearTimeout(window.renderSyncCallTO);
}
function doRender () {
renderSync(apikey);
}
window.renderSyncCallTO = setTimeout(doRender, 400);
}
b. Copy the code snippet below and name it as ecal-sync-button.component.html
file.
<button class='ecal-sync-widget-button' [attr.data-ecal-widget-id]='widgetId'>
Sync to Calendar
</button>
c. Copy the code snippet below and name it as ecal-sync-button.component.ts
file.
import { OnInit, Component, Input } from '@angular/core';
declare function renderEcalSyncButton(apikey:string): void;
@Component({
selector: 'ecal-sycn-button',
templateUrl: './ecal-sync-button.component.html',
inputs: ['data-ecal-widget-id'],
})
class EcalSyncButton implements OnInit {
@Input() widgetId:string = '';
@Input() apikey:string = '';
constructor() {}
ngOnInit() {
this.renderSync();
}
renderSync(){
renderEcalSyncButton(this.apikey);
}
}
export default EcalSyncButton;
a. Open the angular.json file.
b. Find the property of projects.[app-name].architect.build.options.scripts
.
c. Add src/ecal/ecal-angular.js
in the scripts array.
Example Code
{
"projects": {
"[APP-NAME]": {
"architect": {
"build": {
...
"options": {
...
"scripts": [
"src/ecal/ecal-angular.js"
],
...
},
}
}
}
}
}
a. Open src/app/app.module.ts
.
b. Import EcalSyncButton component to the module.
import EcalSyncButton from '../ecal/ecal-sync-button.component';
c. Add EcalSyncButton component in @NgModule declarations.
@NgModule({
declarations: [
...
EcalSyncButton,
...
],
a. Open src/app/app.component.html
or other angular component template file.
b. Finally, embed ecal-sync-button component with the API Key and Widget ID that you noted in step 1.
<ecal-sycn-button apikey="INSERT_YOUR_API_KEY" widgetId="INSERT_YOUR_WIDGET_ID" />
By default, the HTML element you apply the ecal-sync-widget-button class to will be replaced with the default ECAL button styling. To override this, simply add the data-ecal-no-styling attribute to the HTML element.
<ecal-sycn-button apikey="INSERT_YOUR_API_KEY" widgetId="INSERT_YOUR_WIDGET_ID" data-ecal-no-styling />
For further information on any of the above, refer to the detailed API reference or contact ECAL support using the chat in your ECAL Admin or support@ecal.com.