gpt4 book ai didi

javascript - AngularJS : controller fails when minified

转载 作者:行者123 更新时间:2023-12-02 17:17:18 25 4
gpt4 key购买 nike

该 Controller 抛出 unknown provider ,我知道我需要准备 Controller 以防止缩小和依赖注入(inject)问题。但它不起作用。它只是为了展示我如何使用我的依赖项。

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

最佳答案

指令的 Controller 就像其他东西一样被依赖注入(inject)。将其更改为使用数组语法,您将受益匪浅:

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

关于javascript - AngularJS : controller fails when minified,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24312512/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com