1

I have an AngularJS factory into which I'm injecting a service.

I can see the service getting inject when I debug in Chrome (at the line return service;), but it's not accessible further down in one of my functions.

See function updateWidget where I try to call reportsContext.buildAggrFuncFromKriGrid

(function() {
    'use strict';
    angular.module('app').factory('widgetLinkingFactory', ['$q', 'reportsContext', linking]);

    function linking($q, reportsContext) {

        var service = {
            linkCharts: linkCharts
        };

        return service;

        function linkCharts(parId, widgets, parentWidgetData) {

            _.each(widgets, function(wid) {
                if (wid.dataModelOptions.linkedParentWidget) {
                    updateWidget(wid, parentWidgetData);
                }
            });
        }
    }

    function updateWidget(widget, parWidData) {

        // PULL RISK MEASURES ON CHILD WIDGET 
        var rm = widget.dataModelOptions.riskMeasures;

        // ******* WHY IS 'reportsContext' SERVICE IS UNDEFINED HERE ?????
        var aggrFuncArray = reportsContext.buildAggrFuncFromKriGrid(rm);

        var cubeVectors = aggrFuncArray[0];
        var aggrFunc = aggrFuncArray[1];

        return true;
    }
})();
dfsq
  • 191,768
  • 25
  • 236
  • 258
bob.mazzo
  • 5,183
  • 23
  • 80
  • 149

1 Answers1

2

You need to move updateWidget function into linkCharts so that reportsContext will be available there:

(function() {
    'use strict';
    angular.module('app').factory('widgetLinkingFactory', ['$q', 'reportsContext', linking]);

    function linking($q, reportsContext) {

        var service = {
            linkCharts: linkCharts
        };

        return service;

        function linkCharts(parId, widgets, parentWidgetData) {

            _.each(widgets, function(wid) {
                if (wid.dataModelOptions.linkedParentWidget) {
                    updateWidget(wid, parentWidgetData);
                }
            });
        }

        function updateWidget(widget, parWidData) {

            // PULL RISK MEASURES ON CHILD WIDGET 
            var rm = widget.dataModelOptions.riskMeasures;

            var aggrFuncArray = reportsContext.buildAggrFuncFromKriGrid(rm);

            var cubeVectors = aggrFuncArray[0];
            var aggrFunc = aggrFuncArray[1];

            return true;
        }
    }

})();
dfsq
  • 191,768
  • 25
  • 236
  • 258
  • yup, yet another one of my DUMB mistakes. – bob.mazzo Dec 03 '15 at 22:45
  • I can now see my `reportsContext` service fully accessible; however, I cannot see `$q`. Is there any issue injecting that ? – bob.mazzo Dec 03 '15 at 22:46
  • 1
    It should be available, check your code, probably something specific for your set up interferes. – dfsq Dec 03 '15 at 22:49
  • Incredibly, no. $q is not available. i also tried $http. Still nothing. WEIRD. – bob.mazzo Dec 03 '15 at 23:07
  • maybe the providers are simply not available, as per this post - http://stackoverflow.com/questions/19719729/angularjs-injecting-factory-from-another-module-into-a-provider – bob.mazzo Dec 03 '15 at 23:57