0

This controller throws unknown provider, I understand that I need to prepare my controller to prevent minified and dependency injection problems. But it is not working. it is simplyfied to show how I am using my dependencies.

adminApp.directive('cashflower', ['$compile', '$timeout', '$http', 'global', function ($compile, $timeout, $http, global) {
var CashFlow = function (init) {
    this.curr = init.curr; // some more
};
return {
    restrict: 'E',
    replace: true,
    templateUrl: '/AppAdmin/Templates/cashflower.html',
    controller: function ($scope) {

        $scope.decimalP = global.regexp.decimalP;

        $scope.$watch('total', function () {
            calculateRemaining();
        });

        $scope.toggleIsCurrLocked = function () {
            $scope.isCurrLocked = !$scope.isCurrLocked;
            if (!$scope.isCurrLocked) {
                $timeout(function () {
                    $scope.isCurrLocked = true;
                }, 20000);
            }
        };

        $scope.placement = $scope.placement ? $scope.placement : 'bottom';
        $scope.failed = false;
    },
    link: function (scope, element) {
        var goForIt = function () {
            $http({ method: 'GET', url: '/AppAdmin/Templates/cashflowerpopover.html' }).
            success(function (data) {
                element.popover({
                    html: true,
                    placement: scope.placement ? scope.placement : 'bottom',
                    content: $compile(data)(scope)
                });
                scope.failed = false;
            })
            .error(function () {
                scope.failed = true;
            });
        };
        goForIt();
        angular.element(element).click(function () {
            if (scope.failed) {
                goForIt();
            }
        });
    },
    scope: {
        someScope: '='
    }
};
}]);
0

1 Answer 1

2

Controllers for directives are dependency injected just like anything else. Change it to use the array syntax and you will be golden:

controller: ['$scope', function($scope){
  //Controller Impl
}]
Sign up to request clarification or add additional context in comments.

2 Comments

global is my service, it works fine in other directives
@bto.rdz - Ok, just wanted to make sure it wasn't failing there.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.