Angular Web应用程序中的错误,现在显示任何视图

时间:2016-04-03 03:32:28

标签: javascript ruby-on-rails angularjs

我正在关注正在制作Angular on Rails的教程。 这是项目的JSFiddle URL:https://jsfiddle.net/dcbavw4e/4/

我目前正在收到2个错误:

 1. Uncaught SyntaxError: Unexpected token .
Error occuring at :     .controller('MainCtrl', ['$scope', 'posts', function($scope, posts) {

2. angular.js:68 Uncaught Error: [$injector:modulerr] Failed to instantiate module flapperNews due to:
Error: [$injector:nomod] Module 'flapperNews' 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.4.9/$injector/nomod?p0=flapperNews
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:68:12
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:2006:17
    at ensure (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:1930:38)
    at module (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:2004:14)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:4447:22
    at forEach (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:341:20)
    at loadModules (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:4431:5)
    at createInjector (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:4356:11)
    at doBootstrap (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:1677:20)
    at bootstrap (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:1698:12)
http://errors.angularjs.org/1.4.9/$injector/modulerr?p0=flapperNews&p1=Erro….googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.9%2Fangular.js%3A1698%3A12)

我不确定我做错了什么因为我在index.htmlapp.js检查了应用名称,但它们都匹配。

1 个答案:

答案 0 :(得分:1)

您的代码中存在一些语法错误。在小提琴的第24行,你使用';'它打破了链条,因此控制器'MainCtrl'不会附加到模块'flapperNews'。 (还有一些错误。)请参阅评论中的小提琴

.factory('posts', [function(){
    var o = {
        posts: []
    };
    return o;
}]);