Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minifying AngularJS script that includes a custom filter

I've looked at three different ways to minify AngularJS scripts. However, none of them explains how I'm supposed to take into account custom filters. I have my code formatted like this:

app.controller("App", ["$scope","$timeout", function($scope, $timeout){...}]);

Along with some additional code like this:

app.filter('unsafe', function($sce) {
    return function(val) {
        return $sce.trustAsHtml(val);
    };
});

When I minify all of the above, the filter isn't recognized anymore. How do I go about prepping my code for minification?

like image 931
Grant Park Avatar asked Mar 14 '23 15:03

Grant Park


1 Answers

app.filter('unsafe', ['$sce', function($sce) {
    return function(val) {
        return $sce.trustAsHtml(val);
    };
}]);

When minified that $sce is transformed in a variable called a so that it takes less space possible but angular doesn't recognize it anymore so you need to declare that that first parameter is still $sce but with another variable name

like image 192
Matteo Cardellini Avatar answered Mar 23 '23 16:03

Matteo Cardellini