Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 基本角度:未捕获的语法错误:意外标记_Javascript_Angularjs_Angular Ui Router - Fatal编程技术网

Javascript 基本角度:未捕获的语法错误:意外标记

Javascript 基本角度:未捕获的语法错误:意外标记,javascript,angularjs,angular-ui-router,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/

我正在按照一个教程创建一个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)
这里发生了什么?对不起,我不太熟悉这个问题

我在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];
}]);
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>

删除
就在您的
PostsCtrl
控制器定义上方:

}]) //here
.controller('PostsCtrl'

干扰控制器的链接。

删除
就在您的
PostsCtrl
控制器定义上方:

}]) //here
.controller('PostsCtrl'

正在干扰控制器的链接。

尝试在服务器(IIS或Apache)下打开应用程序,不要只在浏览器中打开index.html

尝试在服务器(IIS或Apache)下打开应用程序,不要只在浏览器中打开index.html

检查app.js的第46行,用我删除时发生的情况更新问题;第46行代码中没有“replaceState”或“History”。请检查app.js的第46行?我会更新问题,说明删除时会发生什么;第46行代码中没有“replaceState”或“History”。嘿,我已经尝试过了,但这给了我另一个错误。我在最后添加了对上述问题的错误描述。这应该是一个单独的问题。你能帮忙吗?我编辑了这个问题,使之成为这个问题。看起来像是服务器问题,但我不确定。最好的办法是作为一个单独的问题提问,同时详细说明您在服务器中使用了什么,等等。嘿,我试过了,但这给了我另一个错误。我在最后添加了对上述问题的错误描述。这应该是一个单独的问题。你能帮忙吗?我编辑了这个问题,使之成为这个问题。看起来像是服务器问题,但我不确定。最好的办法是作为一个单独的问题提问,同时详细说明您在服务器中使用了什么。