0

I cannot convince why uglify not working for my app.js (angularjs) file. Here is my part of js file.

(function() {
    'use strict';

    var coursesApp = angular.module('pwaCoursesApp',['ngRoute', 'ngSanitize'])
    coursesApp.config(['$routeProvider', '$locationProvider', function( $routeProvider, $locationProvider){
        $routeProvider
        .when('/', 
            {
                templateUrl: '/home.html',
                controllerAs: 'homeCtrl'
            })
        .otherwise({redirectTo:'/'});
    }]);

    coursesApp.controller('homeCtrl', function($scope, $http) {

    });
})();

and here is my gulp uglify script

gulp.task('scripts', function() {
  var sources = [
    'node_modules/es6-promise/dist/es6-promise.js',
    'app/scripts/app.js',
    ];

  return gulp.src(sources)
    .pipe($.concat('main.min.js'))
    .pipe($.uglify())
    .pipe(gulp.dest('dist/scripts'))
    .pipe($.size({title: 'scripts'}));
});

and gulp told me that it was successfully uglify but when I render my app it's not working at all and show me that error message.

main.min.js:2 Error: [$injector:unpr] http://errors.angularjs.org/1.3.8/$injector/unpr?p0=tProvider%20%3C-%20t%20%3C-%20homeCtrl
    at http://localhost:3000/scripts/main.min.js:1:6739
    at http://localhost:3000/scripts/main.min.js:1:22851
    at Object.r [as get] (http://localhost:3000/scripts/main.min.js:1:21847)
    at http://localhost:3000/scripts/main.min.js:1:22924
    at r (http://localhost:3000/scripts/main.min.js:1:21847)
    at Object.i [as invoke] (http://localhost:3000/scripts/main.min.js:1:22103)
    at l.instance (http://localhost:3000/scripts/main.min.js:2:10025)
    at http://localhost:3000/scripts/main.min.js:2:1403
    at o (http://localhost:3000/scripts/main.min.js:1:7233)
    at x (http://localhost:3000/scripts/main.min.js:2:1387) <div ng-view="" class="ng-scope">

But not uglify, it's working smoothly. Please let me know what I missed out. Thanks.

4
  • can you share how homeCtrl is declared ? Commented May 14, 2017 at 4:41
  • Just noticed, ull need to have controller declare ld in the route config if u want to use controllerAs. Commented May 14, 2017 at 9:14
  • @Searching can u show some example to get correct answer? Commented May 14, 2017 at 9:15
  • 1
    Replying from fone, but all u need to do is in rename controllerAs to controller. docs.angularjs.org/api/ngRoute/service/$route#example Commented May 14, 2017 at 9:20

1 Answer 1

1

This generally happens when you injected your dependencies with the shortcut syntax.

angular
    .module('myapp')
    .controller('myController', function ($rootScope, $location) {

})

is an example of shortcut syntax.

It's bad because dependencies are not written in a string. So when you minify it, it'll become something like

function(a,b)

which obvisouly doesn't work.

Use $inject instead.

See here for more infos.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.