<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to use my own AngularJS controllers with 3.0.1 dashboards?]]></title><description><![CDATA[<p dir="auto">I need to export point data in xlsx form and would rather not meddle with excel-reports due to only being able to have one report in the free version of the module. For this I planned to use something like in this example</p>
<p dir="auto"><a href="http://jsfiddle.net/TheSharpieOne/XNVj3/1/" rel="nofollow ugc">http://jsfiddle.net/TheSharpieOne/XNVj3/1/</a></p>
<p dir="auto">However, I'm facing problems when trying to get any of my own angular functions work. This is how I tried to test things out:</p>
<p dir="auto">In my HTML file:</p>
<pre><code>&lt;div ng-controller="myCtrl"&gt;
	&lt;md-button class="md-raised" ng-click="test()"&gt;Push me&lt;/md-button&gt;
&lt;/div&gt;
&lt;script src="export.js"&gt;&lt;/script&gt;
</code></pre>
<p dir="auto">In my .JS file</p>
<pre><code>var testing = angular.module('testing', []);
testing.controller('myCtrl',[$scope, 
function ($scope) {
	$scope.test = function(){
		console.log('Logg meh');
	}
}]);
</code></pre>
<p dir="auto">I'm getting a reference error stating that angular is not defined. So should I have the reference in my export.js file? Or is there a mango file in which I should include my own controllers?</p>
]]></description><link>https://forum.mango-os.com/topic/2227/how-to-use-my-own-angularjs-controllers-with-3-0-1-dashboards</link><generator>RSS for Node</generator><lastBuildDate>Thu, 14 May 2026 01:03:02 GMT</lastBuildDate><atom:link href="https://forum.mango-os.com/topic/2227.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 23 Apr 2016 16:53:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to use my own AngularJS controllers with 3.0.1 dashboards? on Sun, 24 Apr 2016 02:42:45 GMT]]></title><description><![CDATA[<p dir="auto">I finally got it to work. Thank you a lot, this would have been quite a bit harder for me to achieve without your fast and accurate help!</p>
]]></description><link>https://forum.mango-os.com/post/11475</link><guid isPermaLink="true">https://forum.mango-os.com/post/11475</guid><dc:creator><![CDATA[nyoa]]></dc:creator><pubDate>Sun, 24 Apr 2016 02:42:45 GMT</pubDate></item><item><title><![CDATA[Reply to How to use my own AngularJS controllers with 3.0.1 dashboards? on Sat, 23 Apr 2016 23:54:42 GMT]]></title><description><![CDATA[<p dir="auto">You're missing the single quotes around $scope. See below.</p>
<pre><code>myApp.controller('myCtrl',['$scope', 
function ($scope) {
	$scope.test = function(){
		console.log('Logg meh');
	};
}]);

</code></pre>
<p dir="auto">The scope variable is injected into your controller using Angular's dependency injection. Have a look <a href="https://docs.angularjs.org/guide/di" rel="nofollow ugc">here for more information on the syntax</a>.</p>
]]></description><link>https://forum.mango-os.com/post/11474</link><guid isPermaLink="true">https://forum.mango-os.com/post/11474</guid><dc:creator><![CDATA[Jared Wiltshire]]></dc:creator><pubDate>Sat, 23 Apr 2016 23:54:42 GMT</pubDate></item><item><title><![CDATA[Reply to How to use my own AngularJS controllers with 3.0.1 dashboards? on Sat, 23 Apr 2016 20:39:32 GMT]]></title><description><![CDATA[<p dir="auto">Thank you for your help so far. Should my .js file look like this with the added custom function? I'm getting ReferenceError: $scope is not defined</p>
<pre><code>/**
 * @copyright 2016 {@link http://infiniteautomation.com|Infinite Automation Systems, Inc.} All rights reserved.
 * @author Jared Wiltshire
 */

define([
    'angular',
    'mango-3.0/maMaterialDashboards'
], function(angular, maMaterialDashboards) {
'use strict';

var myApp = angular.module('myApp', ['maMaterialDashboards']);

myApp.run(['$rootScope', function($rootScope) {
    $rootScope.pi = function() {
        return Math.PI;
    }
}]);

myApp.directive('myCustomComponent', function() {
    return {
        restrict: 'E',
        scope: {
            name: '@'
        },
        template: '&lt;span&gt;Hello {{name}}!&lt;/span&gt;'
    };
});

myApp.controller('myCtrl',[$scope, 
function ($scope) {
	$scope.test = function(){
		console.log('Logg meh');
	};
}]);

angular.element(document).ready(function() {
    angular.bootstrap(document.documentElement, ['myApp']);
});

}); // define
</code></pre>
<p dir="auto">Here is the HTML file just in case. I changed it to the template file because i thought it would be a lot easier to troubleshoot in case it was needed. The main thing I need right now in any case is to get the custom functions work before actually adding them to my dashboard</p>
<pre><code>&lt;!DOCTYPE html&gt;
&lt;html lang="en" ma-app="maMaterialDashboards"&gt;
&lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;meta http-equiv="x-ua-compatible" content="ie=edge"&gt;
    &lt;title&gt;My Custom App&lt;/title&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
    
    &lt;link rel="stylesheet" href="/resources/angular-csp.css"&gt;&lt;/link&gt;
    &lt;link rel="stylesheet" href="../vendor/angular-material/angular-material.css"&gt;
    &lt;link rel="stylesheet" href="../vendor/material-design-icons/iconfont/material-icons.css"&gt;
    &lt;link rel="stylesheet" href="../vendor/mdPickers/mdPickers.css"&gt;
&lt;/head&gt;

&lt;body layout="column"&gt;
    &lt;div ng-if="appLoading"&gt;
        &lt;span&gt;App is loading..&lt;/span&gt;
    &lt;/div&gt;

    &lt;div ng-cloak layout="column" flex&gt;
        &lt;!-- Your content here --&gt;
        &lt;span&gt;Pi is {{pi() | number:5}}.&lt;/span&gt;
        &lt;my-custom-component name="John Smith"&gt;&lt;my-custom-component&gt;
    &lt;/div&gt;
	&lt;div ng-controller="myCtrl"&gt;
		&lt;md-button class="md-raised" ng-click="test()"&gt;Push me&lt;/md-button&gt;
	&lt;/div&gt;
    &lt;script src="/resources/require.js"&gt;&lt;/script&gt;
    &lt;script src="/resources/loaderConfig.js"&gt;&lt;/script&gt;
    &lt;script src="../js/loaderConfig.js"&gt;&lt;/script&gt;
	&lt;script type="text/javascript"&gt;require(['dashboards/fosfaattifosfori/export']);&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;

</code></pre>
<p dir="auto">Thanks a lot for your help!</p>
]]></description><link>https://forum.mango-os.com/post/11473</link><guid isPermaLink="true">https://forum.mango-os.com/post/11473</guid><dc:creator><![CDATA[nyoa]]></dc:creator><pubDate>Sat, 23 Apr 2016 20:39:32 GMT</pubDate></item><item><title><![CDATA[Reply to How to use my own AngularJS controllers with 3.0.1 dashboards? on Sat, 23 Apr 2016 18:58:00 GMT]]></title><description><![CDATA[<p dir="auto">So basically for what you are trying to do, which is extend a mango dashboard app with your own logic you will want to start with the extendApp template. I'm sorry I know it is a bit confusing but here are the steps:</p>
<p dir="auto">Start with the Extend app template and paste in your custom HTML that you have started on:</p>
<pre><code>&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;meta http-equiv="x-ua-compatible" content="ie=edge"&gt;
    &lt;title&gt;My Custom App&lt;/title&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
    
    &lt;link rel="stylesheet" href="/resources/angular-csp.css"&gt;&lt;/link&gt;
    &lt;link rel="stylesheet" href="../vendor/angular-material/angular-material.css"&gt;
    &lt;link rel="stylesheet" href="../vendor/material-design-icons/iconfont/material-icons.css"&gt;
&lt;/head&gt;

&lt;body layout="column"&gt;
    &lt;div ng-if="appLoading"&gt;
        &lt;span&gt;App is loading..&lt;/span&gt;
    &lt;/div&gt;

    &lt;div id="maincontainer" ng-cloak&gt;........YOUR HTML.......&lt;/div&gt;


    &lt;script src="/resources/require.js"&gt;&lt;/script&gt;
    &lt;script src="/resources/loaderConfig.js"&gt;&lt;/script&gt;
    &lt;script src="../js/loaderConfig.js"&gt;&lt;/script&gt;
	&lt;script type="text/javascript"&gt;require(['dashboards/templates/extendApp']);&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p dir="auto">Add your custom css file and the mdPickers CSS ref to the head which is missing from the template (a bug we need to add it to this template for datepickers):</p>
<pre><code> &lt;link rel="stylesheet" type="text/css" href="tyylit.css"&gt;
&lt;link rel="stylesheet" href="../vendor/mdPickers/mdPickers.css"&gt;
</code></pre>
<p dir="auto">See that require JS command at the bottom? This is what your will need to update to your custom JS file. So if your export.js  and index.html is in a folder called custom you will reference it like (the .js is left out when using require):</p>
<pre><code>&lt;script type="text/javascript"&gt;require(['dashboards/custom/export']);&lt;/script&gt;
</code></pre>
<p dir="auto">Now you will need to update the export.js to use the JS portion of the extendApp template.<br />
(<a href="http://localhost:8080/modules/dashboards/web/mdAdmin/#/dashboard/examples/templates/extend-app" rel="nofollow ugc">http://localhost:8080/modules/dashboards/web/mdAdmin/#/dashboard/examples/templates/extend-app</a>)</p>
<pre><code>/**
 * @copyright 2016 {@link http://infiniteautomation.com|Infinite Automation Systems, Inc.} All rights reserved.
 * @author Jared Wiltshire
 */

define([
    'angular',
    'mango-3.0/maMaterialDashboards'
], function(angular, maMaterialDashboards) {
'use strict';

var myApp = angular.module('myApp', ['maMaterialDashboards']);

myApp.run(['$rootScope', function($rootScope) {
    $rootScope.pi = function() {
        return Math.PI;
    }
}]);

myApp.directive('myCustomComponent', function() {
    return {
        restrict: 'E',
        scope: {
            name: '@'
        },
        template: '&lt;span&gt;Hello {{name}}!&lt;/span&gt;'
    };
});

angular.element(document).ready(function() {
    angular.bootstrap(document.documentElement, ['myApp']);
});

}); // define
</code></pre>
<p dir="auto">you should now be able to define your controller on the myApp module. So below the directive definition block add:</p>
<pre><code>myApp.controller('myCtrl',[$scope, 
function ($scope) {
	$scope.test = function(){
		console.log('Logg meh');
	}
}]);
</code></pre>
<p dir="auto">The function defined in the controller should now be available to use within your &lt;div ng-controller="myCtrl"&gt;...&lt;/div&gt;</p>
<p dir="auto">There is also a directive definition template in the JS file that you can use to create your own HTML directives that you would use like &lt;my-custom-component&gt;&lt;/my-custom-component&gt; (camel case in JS directive definition &gt; dash lowercase in html)</p>
<p dir="auto">If you still have issues please update the post with complete HTML / JS files.</p>
<p dir="auto">Cheers<br />
Will</p>
]]></description><link>https://forum.mango-os.com/post/11472</link><guid isPermaLink="true">https://forum.mango-os.com/post/11472</guid><dc:creator><![CDATA[Will Geller]]></dc:creator><pubDate>Sat, 23 Apr 2016 18:58:00 GMT</pubDate></item><item><title><![CDATA[Reply to How to use my own AngularJS controllers with 3.0.1 dashboards? on Sat, 23 Apr 2016 17:48:06 GMT]]></title><description><![CDATA[<p dir="auto">Thank you for a fast reply!</p>
<p dir="auto">Here is my complete HTML file called index.html</p>
<pre><code>&lt;!DOCTYPE html&gt;
&lt;html lang="en" ma-app="maMaterialDashboards"&gt;
	&lt;head&gt;
		&lt;meta charset="utf-8"&gt;
		&lt;meta http-equiv="x-ua-compatible" content="ie=edge"&gt;
		&lt;title&gt;JAMK Fosfaattianalysaattori&lt;/title&gt;
		&lt;link rel="icon" href="/images/favicon.ico"&gt;
		&lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
		
		&lt;link rel="stylesheet" type="text/css" href="tyylit.css"&gt;
		&lt;link rel="stylesheet" href="/resources/angular-csp.css"&gt;&lt;/link&gt;
		&lt;link rel="stylesheet" href="../vendor/angular-material/angular-material.css"&gt;
		&lt;link rel="stylesheet" href="../vendor/material-design-icons/iconfont/material-icons.css"&gt;
		&lt;link rel="stylesheet" href="../vendor/mdPickers/mdPickers.css"&gt;
	&lt;/head&gt;
	&lt;body layout="column"&gt;
		&lt;div ng-if="appLoading"&gt;
			&lt;img src="loader.gif" alt="App loading.." style="margin-left:50%;margin-top:25%"&gt;
		&lt;/div&gt;
		&lt;div id="maincontainer" ng-cloak&gt;
			&lt;header&gt;
				&lt;img src="jamkfi_tunnus_sininen_suomi.png" alt="jamk.fi" style="width:50%;height:50%;margin-left:25%;"&gt; 
			&lt;/header&gt;
			&lt;div id="textContainer"&gt;
				&lt;img src="header.jpg" alt="Fosfaattifosfori PO4-P [mg/l]" style="width:50%;height:50%;margin-left:25%;"&gt; 
			&lt;/div&gt;
			&lt;div&gt;
			
				&lt;ma-get-point-value point-xid="DP_355369" point="point1"&gt;&lt;/ma-get-point-value&gt;

				&lt;ma-point-values id="testi" point="point1" values="point1Values" from="from" to="to" rollup="AVERAGE" rollup-interval="1 minutes"&gt;
				&lt;/ma-point-values&gt;

				&lt;ma-serial-chart id="chartti" style="height: 500px; width: 100%" series-1-values="point1Values" series-1-point="point1" options="{chartCursor:{categoryBalloonDateFormat:'YYYY-MM-DD HH:NN'}, chartScrollbar:{oppositeAxis: false, scrollbarHeight: 40,offset: 25, graph:'DP_355369',updateOnReleaseOnly: true}}"&gt;
				&lt;/ma-serial-chart&gt;
				
				&lt;div layout="row"&gt;
					&lt;md-input-container flex="33" class="no-errors-spacer"&gt;
					   &lt;label&gt;Date preset&lt;/label&gt;
					   &lt;ma-date-range-picker from="from" to="to" preset="LAST_1_DAYS" update-interval="1 minutes"&gt;&lt;/ma-date-range-picker&gt;
					&lt;/md-input-container&gt;
					&lt;md-input-container flex="33" class="no-errors-spacer"&gt;
					   &lt;label&gt;From date&lt;/label&gt;
					   &lt;ma-date-picker ng-model="from"&gt;&lt;/ma-date-picker&gt;
					&lt;/md-input-container&gt;
					&lt;md-input-container flex="33" class="no-errors-spacer"&gt;
						&lt;label&gt;To date&lt;/label&gt;
						&lt;ma-date-picker ng-model="to"&gt;&lt;/ma-date-picker&gt;
					&lt;/md-input-container&gt;
				&lt;/div&gt;
				&lt;div&gt;
					&lt;div&gt;
						&lt;md-button class="md-raised" ng-click="showStats=true;showData=false" ng-hide="showStats"&gt;Statistics&lt;/md-button&gt;
						&lt;md-button class="md-raised" ng-click="showStats=false;showData=false" ng-show="showStats"&gt;Statistics&lt;/md-button&gt;
						&lt;md-button class="md-raised" ng-click="showData=true;showStats=false" ng-hide="showData"&gt;Data&lt;/md-button&gt;
						&lt;md-button class="md-raised" ng-click="showData=false;showStats=false" ng-show="showData"&gt;Data&lt;/md-button&gt;
					&lt;/div&gt;
					&lt;div ng-controller="myCtrl"&gt;
						&lt;md-button class="md-raised" ng-click="test()"&gt;Push me&lt;/md-button&gt;
					&lt;/div&gt;
					&lt;div layout="row" ng-show="showStats" class="ng-hide"&gt;
						&lt;ma-point-statistics point="point1" from="from" to="to" statistics="statsObj"&gt;&lt;/ma-point-statistics&gt;

						&lt;ma-statistics-table id="statsTable" statistics="statsObj"&gt;&lt;/ma-statistics-table&gt;
					&lt;/div&gt;
                                        &lt;div layout="row" ng-show="showData" class="ng-hide"&gt;
						&lt;table width="100%" height="500px"&gt;
							&lt;thead&gt;
								&lt;tr&gt;
									&lt;th&gt;Value&lt;/th&gt;
									&lt;th&gt;Time&lt;/th&gt;
								&lt;/tr&gt;
							&lt;/thead&gt;
							&lt;tbody&gt;
								&lt;tr ng-repeat="item in point1Values"&gt;
									&lt;td&gt;{{item.value}}&lt;/td&gt;
									&lt;td&gt;{{item.timestamp | moment:'format':'lll' }}&lt;/td&gt;
								&lt;/tr&gt;
							&lt;/tbody&gt;
						&lt;/table&gt;
					&lt;/div&gt;
				&lt;/div&gt;
			&lt;/div&gt;
		&lt;/div&gt;
		&lt;script src="export.js"&gt;&lt;/script&gt;
		&lt;script src="/resources/require.js"&gt;&lt;/script&gt;
		&lt;script src="/resources/loaderConfig.js"&gt;&lt;/script&gt;
		&lt;script src="../js/loaderConfig.js"&gt;&lt;/script&gt;
		&lt;script type="text/javascript"&gt;require(['mango-3.0/bootstrap']);&lt;/script&gt;
	&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p dir="auto">And here is my .js file called export.js. Right now it only has this one test function.</p>
<pre><code>var testing = angular.module('testing', []);
testing.controller('myCtrl',[$scope, 
function ($scope) {
	$scope.test = function(){
		console.log('Logg meh');
	}
}]);
</code></pre>
]]></description><link>https://forum.mango-os.com/post/11471</link><guid isPermaLink="true">https://forum.mango-os.com/post/11471</guid><dc:creator><![CDATA[nyoa]]></dc:creator><pubDate>Sat, 23 Apr 2016 17:48:06 GMT</pubDate></item><item><title><![CDATA[Reply to How to use my own AngularJS controllers with 3.0.1 dashboards? on Sat, 23 Apr 2016 17:34:44 GMT]]></title><description><![CDATA[<p dir="auto">Hi Nyoa,</p>
<p dir="auto">At first glance the code looks OK. But if you are getting the error saying angular is not defined then it must have something to do with angular not getting loaded properly into your JS file.</p>
<p dir="auto">Could you please attach your complete JS and HTML file so I can help debug.</p>
<p dir="auto">Thanks<br />
Will</p>
]]></description><link>https://forum.mango-os.com/post/11470</link><guid isPermaLink="true">https://forum.mango-os.com/post/11470</guid><dc:creator><![CDATA[Will Geller]]></dc:creator><pubDate>Sat, 23 Apr 2016 17:34:44 GMT</pubDate></item></channel></rss>