Flexmonster Software License Agreement (“Agreement”) has been significantly revised and is effective as of September 30, 2024.
The following modifications were made:
The modified version of Flexmonster Software License Agreement is available here.
Downloading, installing, and/or continuing to use Flexmonster Software after September 30, 2024, constitutes Licensee’s acceptance of the terms and conditions of the modified version of Flexmonster Software License Agreement. If Licensee does not agree to any of these terms and conditions, they must cease using Flexmonster Software and must not download, install, use, access, or continue to access Flexmonster Software. By continuing to use Flexmonster Software or renewing the license under License Model or Maintenance after the effective date of any modifications to Agreement, Licensee accepts and agrees to be bound by the terms and conditions of the modified Agreement.
This guide explains how to use Flexmonster methods and events in an Angular application. First, we will create a reference to the FlexmonsterPivot
instance. Then we will use this reference to call methods and subscribe to events.
To access Flexmonster API inside the .component.ts
file, we need a reference to the FlexmonsterPivot
instance. Follow the steps below to create the reference using the @ViewChild decorator:
Step 1. In the HTML template of the component with Flexmonster (e.g., src/app/app.component.html
), assign a template variable to the FlexmonsterPivot
instance (e.g., #pivot
):
<fm-pivot #pivot [toolbar]="true"> </fm-pivot>
Step 2. In the component’s TypeScript file (e.g., src/app/app.component.ts
), import the @ViewChild
decorator:
import { Component, ViewChild } from '@angular/core';
Step 3. In the same TypeScript file, import FlexmonsterPivot
from the Flexmonster wrapper used in your project:
import { FlexmonsterPivot } from 'ngx-flexmonster';
import { FlexmonsterPivot } from 'ng-flexmonster';
Step 4. In the same TypeScript file, use @ViewChild
to inject a reference to the FlexmonsterPivot
instance (e.g., pivotRef
):
@ViewChild('pivot') pivotRef!: FlexmonsterPivot;
pivot
is the template reference variable assigned to the FlexmonsterPivot
instance in step 1.
Depending on the Flexmonster wrapper, the full code from steps 2-4 should look similar to the following:
import { Component, ViewChild } from '@angular/core'; import { FlexmonsterPivot } from 'ngx-flexmonster'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'], }) export class AppComponent { @ViewChild('pivot') pivotRef!: FlexmonsterPivot; // other code }
import { Component, ViewChild } from '@angular/core'; import { FlexmonsterPivot } from 'ng-flexmonster'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'], }) export class AppComponent { @ViewChild('pivot') pivotRef!: FlexmonsterPivot; // other code }
The pivotRef
reference to the FlexmonsterPivot
instance is created.
In this guide, we will use the pivotRef.flexmonster
property, which is a reference to the Flexmonster instance. The pivotRef.flexmonster
gives you access to Flexmonster API.
Call Flexmonster methods using the previously created pivotRef reference:
this.pivotRef.flexmonster.setReport(this.report);
Some methods can also be defined as FlexmonsterPivot input properties:
<fm-pivot #pivot [toolbar]="true" [customizeCell]="customizeCellFunction"> </fm-pivot>
Such methods include:
Check out the sample Angular project for more examples with Flexmonster methods.
See the full list of Flexmonster methods.
There are two ways to subscribe to Flexmonster events:
You can also unsubscribe from an event.
Specify the event's name as the <fm-pivot>
attribute in parentheses and assign an event handler to it:
<fm-pivot #pivot [toolbar]="true" [report]="'https://cdn.flexmonster.com/reports/report.json'" (reportcomplete)="onReportComplete()"> </fm-pivot>
The sample Angular project demonstrates how to subscribe to events by defining them as <fm-pivot>
attributes.
See the full list of Flexmonster events.
Learn more about events in Angular.
Use the previously created pivotRef reference to call the on() method:
this.pivotRef.flexmonster.on('reportcomplete', onReportComplete);
See how the on()
method is used in the sample Angular project.
Check out the full list of Flexmonster events.
Use the off() method to unsubscribe from an event:
this.pivotRef.flexmonster.off('reportcomplete');
This will remove all handlers from the event. To remove a specific handler, pass its name as a second parameter to off()
:
this.pivotRef.flexmonster.off('reportcomplete', onReportComplete);
Note If a handler is specified as an anonymous function, you can remove it only by removing all handlers.
See how the off()
method is used in the sample Angular project.