que1326 que1326 - 10 months ago 49
AngularJS Question

How to return widgetDefinitions with data service in malhar-angular-dashboard?

I have installed the malhar-angular-dashboard module. I do not want to hard code my widgetDefinitions, so I created a service witch will return the array with the widget objects. I am using a rest service to return data such as the widget names, titles, etc. The problem is I get this error and do not know how to resolve :

TypeError: widgetDefs.map is not a function



var serviceInstance = {};

serviceInstance.getInfo = function(){
var request = $http({method: 'GET', url: '/rest/widgets/getListInfoDashboards'})
serviceInstance.widgets = success.data;
$log.debug('serviceInstance.widgets SUCCESS',serviceInstance.widgets);
$log.debug('Error ', error);
$log.debug('serviceInstance.widgets ERROR',serviceInstance.widgets);
return request;

serviceInstance.getAllWidgets = function () {
if (serviceInstance.widgets) {
return serviceInstance.widgets;
} else {
return [];

return serviceInstance;


widgetDefinitions service

.factory('widgetDefinitions',['widgetRestService','$log','$q','$http',function(widgetRestService,$log,$q,$http) {

var widgetDefinitions = [];
return widgetRestService.getInfo().then(function (data) {

var widgets = widgetRestService.getAllWidgets();
$log.debug('widgetsDefs ', widgets);
for (var i = 0; i < widgets.length; i++) {
$log.debug('widgetDefinitions ', widgetDefinitions);
return widgetDefinitions;


TypeError: widgetDefs.map is not a function

widgetDefs: [Object,Object,Object]

widgetDefinitions: [Object,Object,Object]


If I hard-code my widgetDefinitions-service returned array like this it works, if I returned with my rest service doesn`t work(widgetDefs.map is not a function):


Answer Source

Original issue in github has been commented on and closed.

Here's the comment from github:

@pitong Make sure the dashboard options contains a property named widgetDefinitions and it's an array, even if it's empty. Also make sure the the browser version you're using supports the map function for arrays. This map function for array became the ECMA-262 standard in the 5th edition so your browser version might not have it supported.