2016-05-12 103 views
1

即时通过Angular和Firebase应用程序弄湿我的脚。我遇到了以下控制台错误。如果你能帮我弄清楚有什么问题,我无法弄清楚。在AngularJS应用程序中未被捕获的语法错误

而且,我在index.html的inculded这个脚本

console error

app.js:44 Uncaught SyntaxError: Unexpected token . 
angular.js:68 Uncaught Error: [$injector:nomod] Module 'ngClassifieds' 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. 
http://errors.angularjs.org/1.5.0/$injector/nomod?p0=ngClassifieds(anonymous function) @ angular.js:68(anonymous function) @ angular.js:2015ensure @ angular.js:1939module @ angular.js:2013(anonymous function) @ classifieds.ctr.js:6(anonymous function) @ classifieds.ctr.js:86 
angular.js:68 Uncaught Error: [$injector:nomod] Module 'ngClassifieds' 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. 
http://errors.angularjs.org/1.5.0/$injector/nomod?p0=ngClassifieds(anonymous function) @ angular.js:68(anonymous function) @ angular.js:2015ensure @ angular.js:1939module @ angular.js:2013(anonymous function) @ classifieds.fac.js:6(anonymous function) @ classifieds.fac.js:28 
angular.js:68 Uncaught Error: [$injector:nomod] Module 'ngClassifieds' 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. 
http://errors.angularjs.org/1.5.0/$injector/nomod?p0=ngClassifieds(anonymous function) @ angular.js:68(anonymous function) @ angular.js:2015ensure @ angular.js:1939module @ angular.js:2013(anonymous function) @ auth.ctr.js:6(anonymous function) @ auth.ctr.js:44 
angular.js:68 Uncaught Error: [$injector:nomod] Module 'ngClassifieds' 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. 
http://errors.angularjs.org/1.5.0/$injector/nomod?p0=ngClassifieds(anonymous function) @ angular.js:68(anonymous function) @ angular.js:2015ensure @ angular.js:1939module @ angular.js:2013(anonymous function) @ auth.fac.js:6(anonymous function) @ auth.fac.js:18 
angular.js:68 Uncaught Error: [$injector:modulerr] Failed to instantiate module ngClassifieds due to: 
Error: [$injector:nomod] Module 'ngClassifieds' 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. 
http://errors.angularjs.org/1.5.0/$injector/nomod?p0=ngClassifieds 
    at http://localhost:8080/node_modules/angular/angular.js:68:12 
    at http://localhost:8080/node_modules/angular/angular.js:2015:17 
    at ensure (http://localhost:8080/node_modules/angular/angular.js:1939:38) 
    at module (http://localhost:8080/node_modules/angular/angular.js:2013:14) 
    at http://localhost:8080/node_modules/angular/angular.js:4503:22 
    at forEach (http://localhost:8080/node_modules/angular/angular.js:321:20) 
    at loadModules (http://localhost:8080/node_modules/angular/angular.js:4487:5) 
    at createInjector (http://localhost:8080/node_modules/angular/angular.js:4409:19) 
    at doBootstrap (http://localhost:8080/node_modules/angular/angular.js:1691:20) 
    at bootstrap (http://localhost:8080/node_modules/angular/angular.js:1712:12) 
http://errors.angularjs.org/1.5.0/$injector/modulerr?p0=ngClassifieds&p1=Er…3A%2F%2Flocalhost%3A8080%2Fnode_modules%2Fangular%2Fangular.js%3A1712%3A12)(anonymous function) @ angular.js:68(anonymous function) @ angular.js:4526forEach @ angular.js:321loadModules @ angular.js:4487createInjector @ angular.js:4409doBootstrap @ angular.js:1691bootstrap @ angular.js:1712angularInit @ angular.js:1606(anonymous function) @ angular.js:30423trigger @ angular.js:3108defaultHandlerWrapper @ angular.js:3398eventHandler @ angular.js:3386 

在上述错误引用的代码如下:

angular.module('ngClassifieds', ['ngMaterial', 'ui.router', 'firebase']) 


.run(["$rootScope", "$state", function($rootScope, $state) { 
$rootScope.$on("$stateChangeError", function(event, toState, toParams, fromState, fromParams, error) { 
    // We can catch the error thrown when the $requireAuth promise is rejected 
    // and redirect the user back to the home page 
    if (error === "AUTH_REQUIRED") { 
    $state.go("auth"); 
    } 
}); 
}]); 




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

    $mdThemingProvider 
     .theme('default') 
     .primaryPalette('blue-grey') 
     .accentPalette('orange'); 


    $urlRouterProvider.otherwise('/auth'); 


    $stateProvider 
     .state('auth', { 
      url: '/auth', 
      templateUrl: 'components/auth/auth.tpl.html', 
      controller: 'authCtrl', 

     }) 

    $stateProvider 
     .state('masters', { 
      url: '/masters', 
      templateUrl: 'components/classifieds.tpl.html', 
      controller: 'classifiedsCtrl', 
      resolve: { 
       // controller will not be loaded until $requireAuth resolves 
       // Auth refers to our $firebaseAuth wrapper in the example above 
       "currentAuth": ["auth", function(auth) { 
       // $requireAuth returns a promise so the resolve waits for it to complete 
       // If the promise is rejected, it will throw a $stateChangeError (see above) 
       return auth.ref.$requireAuth(); 
       }] 
      } 


     }); 
}); 
+0

此文件ngClassifieds是否在index.html中添加? – Rakeschand

+0

你是否在你的html,body或者其他元素中声明过它:''? – thepio

+0

是的。上面的codereference是文件 - app.js,我已经将它作为脚本包含在index.html – Nosail

回答

1

当你有一个语法错误在一个JavaScript文件中,整个文件不会被解析,所以你的模块最终不会存在你的应用程序的其他JavaScript文件。

所以非常第1个消息是真实的重要一:的SyntaxError

笔者粗略统计,并在那里结束:

return auth.ref.$requireAuth(); 

ref可能引起麻烦尝试auth['ref'].$requireAuth()

2

我会想象你的问题是由这行代码造成的:

.run(["$rootScope", "$state", function($rootScope, $state) { 
    $rootScope.$on("$stateChangeError", function(event, toState, toParams, fromState, fromParams, error) { 
    // We can catch the error thrown when the $requireAuth promise is rejected 
    // and redirect the user back to the home page 
    if (error === "AUTH_REQUIRED") { 
    $state.go("auth"); 
    } 
}); 
}]); 

你正在用分号关闭它,所以配置和其他东西不会运行。您应该删除分号,并像这样:

.run(["$rootScope", "$state", function($rootScope, $state) { 
    $rootScope.$on("$stateChangeError", function(event, toState, toParams, fromState, fromParams, error) { 
    // We can catch the error thrown when the $requireAuth promise is rejected 
    // and redirect the user back to the home page 
    if (error === "AUTH_REQUIRED") { 
     $state.go("auth"); 
    } 
    }); 
}]) 
+0

@thepio ... yup that works !! !!谢谢 – Nosail

+0

很高兴听到你的欢迎:) – thepio

相关问题