我正在使用Angular和firebase应用程序弄湿我的脚。我遇到了以下控制台错误。我很感激,如果你能帮我弄清问题是什么,因为我无法弄明白。
另外,我已经在index.html中加入了这个脚本
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 :(得分: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");
}
});
}])
答案 1 :(得分:1)
如果javascript文件中存在语法错误,则不会解析整个文件,因此您的模块最终不存在应用程序的其他javascript文件。
所以第一条消息是真正重要的消息:SyntaxError
我粗略计算并最终到达那里:
return auth.ref.$requireAuth();
单词ref
可能会导致问题auth['ref'].$requireAuth()