2014-08-28 103 views
0

我使用了一个名为django压缩机的自动缩小工具。然而,django压缩机缩小似乎会引入错误。django压缩机的缩小误差

用分号更新脚本:

前:

var app = angular.module('loginApp', [ 
    "ngRoute", 
    "ngAnimate", 
    "ngTouch", 
    "mobile-angular-ui", 
    "ui.router", 
    "app.factories.storage", 
    "app.controllers.login", 
    "angular-loading-bar" 


]); 


app.config(function ($stateProvider, $urlRouterProvider) { 

    // For any unmatched url, send to /route1 
    $urlRouterProvider.otherwise("/"); 

    $stateProvider 
     .state('login', { 
      url: "/", 
      templateUrl: "/static/html/profile/login.html", 
      controller: "loginController" 
     }) 

     .state('register', { 
      url: "/register", 
      templateUrl: "/static/html/profile/register.html", 
      controller: "loginController" 
     }); 

}); 

后:

var app=angular.module("loginApp",["ngRoute","ngAnimate","ngTouch","mobile-angular-ui","ui.router","app.factories.storage","app.controllers.login","angular-loading-bar"]);app.config(function(e,t){t.otherwise("/");e.state("login",{url:"/",templateUrl:"/static/html/profile/login.html",controller:"loginController"}).state("register",{url:"/register",templateUrl:"/static/html/profile/register.html",controller:"loginController"})}) 

错误:

Error: $injector:modulerr 
Module Error 
Module 'loginApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. 

错误网址:

https://docs.angularjs.org/error/$injector/modulerr...

更新:看来Django的压缩机不是问题,甚至使用在线工具还是给了同样的错误...... ** ** http://jscompress.com/

的结果unminify =没有错误,缩小=错误

这是什么似乎产生错误:

app.config(function(e,t){t.otherwise("/");e.state("login",{url:"/",templateUrl:"/static/html/profile/login.html",controller:"loginController"}).state("register",{url:"/register",templateUrl:"/static/html/profile/register.html",controller:"loginController"})}) 
+0

你使用什么版本的角? – yuvi 2014-08-28 10:48:14

+0

@yuvi我正在使用1.2.19 – Prometheus 2014-08-28 10:50:10

+0

这实际上很奇怪。错误的描述似乎适合[nomod错误]的模板(https://docs.angularjs.org/error/$injector/nomod)而不是'$ injector:modulerr' ...你有' ngRoute'安装? – yuvi 2014-08-28 10:50:17

回答

1

你有两个分号丢失:

app.config(function ($stateProvider, $urlRouterProvider) { 

    // For any unmatched url, send to /route1 
    $urlRouterProvider.otherwise("/") // <--- HERE 

    $stateProvider 
     .state('login', { 
      url: "/", 
      templateUrl: "/static/html/profile/login.html", 
      controller: "loginController" 
     }) 

     .state('register', { 
      url: "/register", 
      templateUrl: "/static/html/profile/register.html", 
      controller: "loginController" 
     }) // <--- HERE 

}); 

它通常是一个好的经验法则,总是通过JSHint最小化之前运行JavaScript代码(尤其是角码这往往真的讨厌被精缩...)

+0

谢谢你对此的帮助。 jshint也是一个很好的链接。 – Prometheus 2014-08-28 11:36:23

+1

@Sputnik至于我对缩小角码而不搞乱名称空间的评论,你应该[阅读此](https://docs.angularjs.org/tutorial/step_05)(向下滚动至“关于缩小的注释”)。通常,您需要始终通过数组注入变量,因此,当您将'$ foo'转换为'a'时,它将保留原始标识。 [ng-annotate](https://github.com/olov/ng-annotate)使这更容易做到 – yuvi 2014-08-28 11:41:50