使用ui.router的Gulp-uglify angularjs应用程序没有移动到下一个$状态

时间:2017-03-10 00:04:53

标签: javascript angularjs minify gulp-uglify

我正在使用带有ngAnnotate和uglify的gulp来缩小我在Angular v1.3.7中的javascript文件。

gulpfile.js

'use strict'
var gulp = require('gulp'),  
   concat = require('gulp-concat'),
   ngAnnotate = require('gulp-ng-annotate'),  
   uglify = require('gulp-uglify'),
   rename = require('gulp-rename');

gulp.task('scripts', function () {    
return gulp.src([
                'Web/js/app.js',
                'Web/js/config.js',
                'Web/js/directives.js',
                'Web/js/filters.js',
                'Web/app/appController.js'])
    .pipe(concat('main.js'))
    .pipe(ngAnnotate({
        remove: true,
        add: true,
        single_quotes: true
    }))
    .pipe(rename('main.min.js')) 
    .pipe(uglify())
    .pipe(gulp.dest('Build/js'));
});
 gulp.task('scripts');

应用程序加载正常,但我无法移动到下一个$状态。更具体地说,登录页面加载,我可以通过网络呼叫告诉我已使用适当的用户信息登录。我使用它的美化(即{})在Chrome中调试它,发现它不会在$ state.go(" index.home")处继续。

这是我的配置文件。我在S.O.做了很多次搜索,但只发现了有关依赖注入的问题。我认为这不是问题,至少在最初阶段。

config.js

(function () {
"use strict";
  var config = function ($stateProvider, $httpProvider, User_Roles, $urlRouterProvider, IdleProvider, vcRecaptchaServiceProvider) {
     $stateProvider
        .state("login", {
            url: "/login",
            templateUrl: "Web/app/login.html",
            controller: "LoginCtrl",
            controllerAs: "ctrl",
            data: {
                pageTitle: "Login"
            }
        })
        .state("index", {
            abstract: true,
            url: "/index",
            templateUrl: "Web/views/common/content.html"
        })
       .state("index.home", {
            url: "/home",
            templateUrl: "Web/app/homePage.html",
            controller: "HomeController",
            controllerAs: "homeCtrl",
            data: {
                pageTitle: "Home",
                authorizedRoles: [User_Roles.admin, User_Roles.provider]
            },
            resolve: {
                auth: function resolveAuthentication(AuthResolver) {
                    return AuthResolver.resolve();
                },
                companyName: function getCompanyName(AppFactory) {
                    return AppFactory.getCompanyName();
                }
            }
        })
}

angular.module("myApp")
    .config(['$stateProvider', '$httpProvider', 'User_Roles', '$urlRouterProvider', 'IdleProvider', 'vcRecaptchaServiceProvider', config]);

})();

该应用程序加载精细和后端调用以授权用户也可以工作。我以为这是我上面的config.js,但它可能在appController.js中。我把它贴在下面。

appController.js

 (function () {
    "use strict";
 var LoginController = function ($scope, $rootScope, Auth_Events, AuthenticFactory, AppFactory, $location, $modal, Session, Idle, $document, $state) {
 var vm = this;
 vm.login = function(credentials){
       AuthenticFactory.login(credentials)
          .then(function(data){ // when uglified it becomes var 'e'
           //if data exists do stuff
          $state.go("index.home") //it reaches here, but it does not go to that $state, nor does it throw any error.
           }, function(error){ //funny thing is that when uglified, this becomes the var 'e' that is the same as the var 'e' that data becomes.
           //if error kick them out
        });
      };
 };
  angular
    .module("myApp")
    .controller("LoginCtrl", ["$scope", "$rootScope", "Auth_Events", "AuthenticFactory", "AppFactory", "$location", "$modal", "Session", "Idle", "$document", "$state", LoginController]);
 })();

浏览器不会抛出任何错误。它只是没有进入主页。  任何帮助深表感谢。提前谢谢!

0 个答案:

没有答案