AngularJS:控制器在缩小时失败

时间:2014-06-19 17:11:49

标签: javascript angularjs minify

这个控制器抛出unknown provider,我知道我需要准备我的控制器以防止缩小和依赖注入问题。但它没有用。简单地说明了我如何使用我的依赖项。

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: '='
    }
};
}]);

1 个答案:

答案 0 :(得分:2)

指令的控制器是依赖注入的,就像其他任何东西一样。改变它以使用数组语法,你将是金色的:

controller: ['$scope', function($scope){
  //Controller Impl
}]