Basic Angular:Uncaught SyntaxError:意外的令牌

Jav*_*ier 0 javascript angularjs angular-ui-router

我正在按照教程创建一个hackernews/reddit克隆,并且由于某种原因,应用程序无法正常工作.

在我的浏览器控制台中,我收到以下错误:

Uncaught SyntaxError: Unexpected token .               app.js:46 
Uncaught Error: [$injector:modulerr]                   angular.js:3857 http://errors.angularjs.org/1.2.19/$injector/modulerr?p0=flapperNews&p1=Err…gleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.19%2Fangular.min.js%3A18%3A139)
Run Code Online (Sandbox Code Playgroud)

这里发生了什么?对不起,我不熟悉这个问题.

我在app.js

angular.module('flapperNews', ['ui.router'])
.config([
'$stateProvider',
'$urlRouterProvider',
function($stateProvider, $urlRouterProvider) {

  $stateProvider
    .state('home', {
      url: '/home',
      templateUrl: '/home.html',
      controller: 'MainCtrl'
    })
    .state('posts', {
      url: '/posts/{id}',
      templateUrl: '/posts.html',
      controller: 'PostsCtrl'
    })

  $urlRouterProvider.otherwise('home');
}])
.factory('posts', [function(){
  var o = {
    posts: []
  };
  return o;
}])
.controller('MainCtrl', [
'$scope',
'posts',
function($scope, posts){
  $scope.posts = posts.posts;
  $scope.incrementUpvotes = function(post){
    post.upvotes += 1;
  }
  $scope.addPost = function(){
    if(!$scope.title || $scope.title === '') { return; }
    $scope.posts.push({
      title: $scope.title, 
      link: $scope.link,
      upvotes: 0
    });
    $scope.title = '';
    $scope.link = '';
  };
}]);
.controller('PostsCtrl', [
'$scope',
'$stateParams',
'$posts',
function($scope, $stateParams, posts) {
  $scope.posts.push({
    titile: $scope.title,
    link: $scope.link,
    upvotes: 0,
    comments: [
      {author: 'Joe', body: 'Cool post!', upvotes: 0},
      {author: 'Bob', body: 'Great idea but everything is wrong!', upvotes: 0}
    ]
  });
  $scope.post = posts.posts[$stateParams.id];
}]);
Run Code Online (Sandbox Code Playgroud)

index.html看起来像这样:

<html>
  <head>
    <title>My Angular App!</title>
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">

    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js"></script>
    <script src="cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.18/angular-ui-router.js"></script>
    <script src="app.js"></script>
    <style> .glyphicon-thumbs-up { cursor:pointer } </style>
  </head>
  <body ng-app="flapperNews">
    <div class="row">
      <div class="col-md-6 col-md-offset-3">
        <ui-view></ui-view>
      </div>
    </div>

    <script type="text/ng-templates" id="/home.html">

        <div class="page-header">
          <h1>Flapper News</h1>
        </div>

        <div ng-repeat="post in posts | orderBy: '-upvotes'">
          <span class="glyphicon glyphicon-thumbs-up"
          ng-click="incrementUpvotes(post)"></span>
          {{post.upvotes}}
          <span style="font-size:20px; margin-left:10px;">
            <a ng-show="post.link" href="{{post.link}}">  
              {{post.title}}
            </a>
            <span ng-hide="post.link">
              {{post.title}}
            </span>
          </span>
        </div>

        <form ng-submit="addPost()" style="margin-top:30px;">
          <h3>Add a new post</h3>

            <div class="form-group">
              <input type="text"
                class="form-control"
                placeholder="Title"
                ng-model="title"></input>
            </div>
            <div class="form-group">
              <input type="text"
              class="form-control"
              placeholder="Link"
              ng-model="link"></input>
            </div>
            <button type="submit" class="btn btn-primary">Post</button>
        </form>
      </script>

      <script type="text/ng-templates" id="/posts.html">
        <div class="page-header">
          <h3>
            <a ng-show="post.link" href="{{post.link}}">
              {{post.title}}
            </a>
            <span ng-hide="post.link">
              {{post.title}}
            </span>
          </h3>
        </div>

        <div ng-repeat="comment in post.comments | orderBy:'-upvotes'">
          <span class="glyphicon glyphicon-thumbs-up"
            ng-click="incrementUpvotes(comment)"></span>
          {{comment.upvotes}} - by {{comment.author}}
          <span style="font-size:20px; margin-left:10px;">
            {{comment.body}}
          </span>
        </div>
      </script>

  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

当我删除; 从第46行我在控制台中得到以下奇怪的东西.它似乎陷入了一个持续错误消息的循环中.

angular.js:9959 Error: Failed to execute 'replaceState' on 'History': A history state object with URL 'file:///Users/Javier/codez/flapper_news/index.html#/home' cannot be created in a document with origin 'null' and URL 'file:///Users/Javier/codez/flapper_news/index.html'.
    at Error (native)
    at te.k.url (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js:39:227)
    at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js:91:187
    at k.$eval (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js:112:319)
    at k.$digest (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js:109:392)
    at k.$apply (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js:113:100)
    at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js:18:239
    at Object.d [as invoke] (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js:35:36)
    at c (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js:18:147)
    at cc (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js:18:356)(anonymous function) @ angular.js:9959(anonymous function) @ angular.js:7298k.$digest @ angular.js:12410k.$apply @ angular.js:12699(anonymous function) @ angular.js:1418d @ angular.js:3917c @ angular.js:1416cc @ angular.js:1430Xc @ angular.js:1343(anonymous function) @ angular.js:21773a @ angular.js:2549(anonymous function) @ angular.js:2822q @ angular.js:325c @ angular.js:2821
angular.js:8467 XMLHttpRequest cannot load file:///home.html. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
Run Code Online (Sandbox Code Playgroud)

Tar*_*gar 5

删除控制器定义;上方PostsCtrl:

}]) //here
.controller('PostsCtrl'
Run Code Online (Sandbox Code Playgroud)

;干扰了控制器的链接.