Adding an AngularJS frontend

October 7th, 2020

This is the 6th article of a Build Java Module for Mango series. You can check all the articles by clicking here

Now that we have some backend to manage the devices. Let’s add some views with AngularJS, so we can use these endpoint from the Mango UI.

First, let’s update our pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
    <description>Energy Metering</description>

We added the frontend-maven-plugin. We also need to create a package.json like this:

  "private": true,
  "name": "energy-metering",
  "version": "4.0.0-SNAPSHOT",
  "description": "Energy metering module",
  "dependencies": {},
  "devDependencies": {
    "@infinite-automation/mango-module-tools": "^2.0.5"
  "author": "Luis Güette <>",
  "license": "UNLICENSED",
  "com_infiniteautomation": {
    "moduleName": "energyMetering"

And a webpack.config.js like this:

const moduleConfig = require('@infinite-automation/mango-module-tools');

module.exports = moduleConfig().then(config => {

        test: /\.raw\.js$/,
        use: [{
            loader: 'raw-loader'

    return config;

Next, we create a energyMetering.js into /web-src directory:

import angular from 'angular';

import overviewPage from './pages/overviewPage/overviewPage';

const energyMetering = angular.module('energyMetering', ['maUiApp']);

energyMetering.component('enmetOverviewPage', overviewPage);

    (maUiMenuProvider) => {
                name: 'ui.generalOverview',
                url: '/overview',
                template: '<enmet-overview-page></enmet-overview-page>',
                weight: 100,
                menuText: 'General Overview',
                menuIcon: 'public',

export default energyMetering;

And inside /web-src/pages/overviewPage we create overviewPage.js:

import htmlTemplate from './overviewPage.html';

class OverviewPageController {
    static get $$ngIsClass() {
        return true;

    static get $inject() {
        return [];

    constructor() {}

    $onInit() {}

export default {
    bindings: {},
    controller: OverviewPageController,
    template: htmlTemplate

And, overviewPage.html :

<h1>Overview Page</h1>

Finally, we need to add into src/com/infiniteautomation/energyMetering directory:

package com.infiniteautomation.energyMetering;
import com.serotonin.m2m2.module.AngularJSModuleDefinition;

public class EnergyMeteringAngularJSModuleDefinition extends AngularJSModuleDefinition {
    public String getJavaScriptFilename() {
        return "/angular/EnergyMetering.js";

Now, execute:

mvn install -Pinstall-module

And you will see that the new module has the added view, like this:

Overview page

Copyright © 2020 Radix IoT, LLC.