2014-08-28 65 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