0

嗨,我在 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"));
    }
}
4

3 回答 3

1

我有同样的问题,但我想我找到了解决方案。它看起来像在本地服务器上(来自 Visual Studio)默认选项 BundleTable.EnableOptimizations 为 false。但是当你在服务器上的 IIS 上发布时是真的。尝试在BundleConfig.cs中添加BundleTable.EnableOptimizations = false

于 2017-09-15T13:10:28.977 回答
0

要启用缩小,请确保以下内容:

  • Config.asax,注册BundlesConfig

    受保护的无效 Application_Start()
    {
        BundlesConfig.RegisterBundles(BundleTable.Bundles);
    }
  • BundleConfig.cs,包含脚本并启用优化

    公共静态无效RegisterBundles(BundleCollection捆绑)
    {
      bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
        "~/Scripts/jquery-{version}.js"));
    
      BundleTable.EnableOptimizations = true;
    }
  • main.html,注册脚本

    @section 脚本 {
      @Scripts.Render("~/bundles/jquery")
    }
    
  • 此外,缩小过程将 $scope 和 $q 更改为随机变量。由于这不会告诉 Angular 注入什么,因此解决方案是将您的依赖项声明为[]

    angular.module("MyApp")
      .controller("MyCtrl", ["$scope", "$q", function($scope, $q) {
      // 你的代码
    }])
    

这只是启用缩小所需的步骤。是一篇关于如何实现这一点的文章

于 2015-12-09T16:41:04.880 回答
0

在您的 ScriptBundle 中删除 angular.min、angular-local-storage.min 并添加它们的未缩小版本

于 2016-01-07T15:44:13.593 回答