2015-12-09 25 views
0

HI我在IIS服務器上發佈AngularJS應用程序後出現問題 我相信這與JavaScript混淆和縮小有關,但我不知道如何解決它...

這是我app.js看怎麼樣

angular.module('app', ['LocalStorageModule', 'angular-loading-bar', 'smart-table', 'mgcrea.ngStrap', 'ngAnimate', 'ngSanitize', 'ngRoute', 'ui.router', 'LocalStorageModule', 'app.filters', 'app.services', 'app.directives', 'app.controllers']) 

.config(['$stateProvider', '$locationProvider', function ($stateProvider, $locationProvider) { 

    $stateProvider 
     .state('home', { 
      url: '/', 
      layout: 'basic', 
      templateUrl: 'views/index', 
      controller: 'HomeCtrl' 

     }) 
     .state('putninalozi', { 
      url: '/putninalozi', 
      layout: 'basic', 
      templateUrl: 'views/PutniNalozi', 
      controller: 'PutniNaloziCtrl' 
     }) 
     .state('profil', { 
      url: '/profil', 
      layout: 'basic', 
      templateUrl: 'views/profil', 
      controller: 'ProfilCtrl' 
     }) 
     .state('login', { 
      url: '/login', 
      layout: 'basic', 
      templateUrl: 'views/login', 
      controller: 'LoginCtrl' 
     }) 
     .state('signup', { 
      url: '/signup', 
      layout: 'basic', 
      templateUrl: 'views/signup', 
      controller: 'SignUpCtrl' 
     }) 
     .state('otherwise', { 
      url: '*path', 
      templateUrl: 'views/404', 
      controller: 'Error404Ctrl' 
     }); 

    $locationProvider.html5Mode(true); 

}]) 

.config(function ($httpProvider) { 
    $httpProvider.interceptors.push('authInterceptorService'); 
}) 

.run(['authService', '$templateCache', '$rootScope', '$state', '$stateParams', function (authService, $templateCache, $rootScope, $state, $stateParams) { 

    authService.fillAuthData(); 
    $rootScope.$state = $state; 
    $rootScope.$stateParams = $stateParams; 

}]); 

再舉例來說,我的控制器的一個看起來像這樣

.controller('LoginCtrl', ['$scope', '$location', '$timeout', '$window', 'authService', function ($scope, $location, $timeout, $window, authService) { 

    $scope.loginData = { 
     userName: "", 
     password: "" 
    }; 

    $scope.message = ""; 

    $scope.login = function() { 

     authService.login($scope.loginData).then(function (response) { 

      $location.path('/putninalozi'); 

     }, 
      function (err) { 
       $scope.message = err.error_description; 
      }); 
    }; 

}]) 

任何想法如何解決這個問題?感謝您的所有意見

我BundleCOnfig.cs看起來像這樣

public class BundleConfig 
{ 
    // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862 
    public static void RegisterBundles(BundleCollection bundles) 
    { 
     bundles.Add(new StyleBundle("~/content/css/app").Include("~/content/app.css") 
                 .Include("~/content/custom.css") 
                 .Include("~/content/loading-bar.css")); 


     // bundles.Add(new ScriptBundle("~/js/jquery").Include("~/scripts/vendor/jquery-{version}.js")); 

     bundles.Add(new ScriptBundle("~/js/app").Include(
       "~/scripts/vendor/angular.min.js", 
       "~/scripts/vendor/smart-table.js", 
       "~/scripts/vendor/angular-strap.min.js", 
       "~/scripts/vendor/angular-strap.tpl.min.js",      
       "~/scripts/app.js", 
       "~/scripts/vendor/jquery-2.0.3.min.js", 
       "~/scripts/vendor/angular-ui-router.js", 
       "~/scripts/vendor/loading-bar.js", 
       "~/scripts/vendor/angular-animate.js", 
       "~/scripts/vendor/angular-route.js", 
       "~/scripts/vendor/angular-sanitize.min.js", 
       "~/scripts/vendor/angular-local-storage.min.js", 
       "~/scripts/vendor/bootstrap.js", 
       "~/scripts/controllers.js", 
       "~/scripts/filters.js", 
       "~/scripts/services.js", 
       "~/scripts/directives.js")); 
    } 
} 
+0

聽起來像微小的問題添加BundleTable.EnableOptimizations =假。你設置了'BundleTable.EnableOptimizations = true;'? – sjokkogutten

+0

不,我沒有代碼的和平 –

+0

你有一個'BundleConfig.cs'所有的JavaScript文件添加到捆綁? – sjokkogutten

回答

0

爲了使微小,確保滿足以下條件:

  • Config.asax,註冊BundlesConfig

    protected void Application_Start() 
    { 
        BundlesConfig.RegisterBundles(BundleTable.Bundles); 
    }
  • BundleConfig.cs,包含腳本並啓用優化

    public static void RegisterBundles(BundleCollection bundles) 
    { 
        bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
        "~/Scripts/jquery-{version}.js")); 
    
        BundleTable.EnableOptimizations = true; 
    }
  • main.html中,註冊腳本

     
    @section scripts { 
        @Scripts.Render("~/bundles/jquery") 
    } 
    
  • 另外的微小變化過程$範圍和$ Q爲隨機變量。因爲這並不n要告訴角度注入什麼,解決的辦法就是聲明你的依賴包裹在[]

     
    angular.module("MyApp") 
        .controller("MyCtrl", ["$scope", "$q", function($scope, $q) { 
        // your code 
    }]) 
    

這只是你需要啓用微小的步驟。 This是如何實際這個

0

的一篇文章中您ScriptBundle刪除angular.min,角本地storage.min並加入他們的unminified版本

0

我有同樣的問題,但我想我找到了解決方案。它看起來像在本地服務器上(來自Visual Studio)默認選項BundleTable.EnableOptimizations爲false。但是當你在serwer上的IIS上發佈是真的。嘗試在BundleConfig.cs

相關問題