ng-classify icon indicating copy to clipboard operation
ng-classify copied to clipboard

Trouble with Provider

Open Karnith opened this issue 9 years ago • 0 comments

Hi,

It's been a year and half since I had the chance to use ng-classify and coffeescript... I seem to be having an issue and can't figure it out.

this is my ng-classify code

# create module
class App extends App('common')
  constructor: ->
    return []

# create provider
class commonConfig extends Provider('common')
  constructor: ->
    @config = {}

    @$get = ->
      { config: @config }

# create the factory 'common'
class common extends Factory('common')
  constructor: ($q, $rootScope, $timeout, commonConfig, logger) ->
    service =
      $broadcast: $broadcast
      $q: $q
      $timeout: $timeout
      logger: logger
      activateController: activateController

    # passthrough of the angular $broadcast service
    $broadcast = ->
      $rootScope.$broadcast.apply $rootScope, arguments

    # global function used to activate a controller once all promises have completed
    activateController = (promises, controllerId) ->
      $q.all(promises).then (eventArgs) ->
        data = controllerId: controllerId
        $broadcast commonConfig.config.controllerActivateSuccessfulEvent, data
        # hide the workingOnIt animation
        #$broadcast commonConfig.config.workingOnItToggleEvent, { show: false }

    return service

which consistently throws a provider issue of commonConfigProvider. yet when I use plain js it works

(function () {
  'use strict';

    // create module
    angular.module('common', [])
    // create provider
    .provider('commonConfig', function () {
        this.config = {};

        this.$get = function () {
            return {
                config: this.config
            };
        };
    })
    // create the factory 'common'
    .factory('common', ['$q', '$rootScope', '$timeout', 'commonConfig', 'logger', common]);

    // function factory 'common'
    function common($q, $rootScope, $timeout, commonConfig, logger) {
        var service = {
                // passthough common angular dependencies
                $broadcast: $broadcast,
                $q: $q,
                $timeout: $timeout,
                // my services
                logger: logger,
                activateController: activateController
            };

        return service;

        // passthrough of the angular $broadcast service
        function $broadcast() {
            return $rootScope.$broadcast.apply($rootScope, arguments);
        }

        // global function used to activate a controller once all promises have completed
        function activateController(promises, controllerId) {
            return $q.all(promises).then(function(eventArgs) {
                var data = { controllerId: controllerId };
                $broadcast(commonConfig.config.controllerActivateSuccessfulEvent, data);
                // hide the workingOnIt animation
                //$broadcast(commonConfig.config.workingOnItToggleEvent, { show: false });
            });
        }
    }
})();

am I missing something? I've spent hours troubleshooting this :(

Karnith avatar Sep 29 '15 04:09 Karnith