AngularJS $ http获取服务“ SyntaxError:意外令牌}”问题

曼尼坎丹S

我正在学习AngularJS。-所以,我就在这里经历的AngularJS教程https://docs.angularjs.org/tutorial/step_07在第7步中,我在使用angularjs $ http服务时遇到语法错误。这是我的应用程序目录结构和文件。

app/
  phone-list/phone-list.component.js
  phone-list/phone-list.module.js
  phone-list/phone-list.template.html
  app.module.js
  phonelist.php
  phonelist.json

电话清单/phone-list.component.js

angular.
  module('phoneList').
  component('phoneList', {
    templateUrl: 'phone-list/phone-list.template.html',
    controller: function PhoneListController($http) {
      var self = this;
      self.orderProp = 'age';

      $http.get('phonelist.json').then(function(response) {
        console.log(response);
        self.phones = response.data;
      });
    }
  });

电话清单/电话清单.module.js

angular.module('phoneList', []);

phone-list / phone-list.template.html

<p>Search: <input ng-model="$ctrl.query" /></p>
<p>
    <select data-ng-model="$ctrl.orderProp">
        <option value="name">Alphabetical</option>
        <option value="age">Newest</option>
    </select>
</p>
<ul>
    <li data-ng-repeat="phone in $ctrl.phones | filter: $ctrl.query | orderBy: $ctrl.orderProp">
        <span>{{phone.name}}</span>
        <p>{{phone.snippet}}</p>
    </li>
</ul>

app.module.js

angular.module('phoneCatApp', ['phoneList']);

phonelist.php

<!DOCTYPE html>
<html>
<head>
    <title>AngularJS | Phone List</title>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
    <script type="text/javascript" src="phone-list/phone-list.module.js"></script>
    <script type="text/javascript" src="phone-list/phone-list.component.js"></script>
    <script type="text/javascript" src="app.module.js"></script>
</head>
<body data-ng-app="phoneCatApp">
    <phone-list></phone-list>
</body>
</html>

phonelist.json

[
  {
    "name": "Nexus S",
    "snippet": "Fast just got faster with Nexus S.",
    "age": 2,
  },
  {
    "name": "Motorola XOOM™ with Wi-Fi",
    "snippet": "The Next, Next Generation tablet.",
    "age": 1,
  },
  {
    "name": "MOTOROLA XOOM™",
    "snippet": "The Next, Next Generation tablet.",
    "age": 4
  }
]

我面临的问题在下面
在此处输入图片说明

潘卡·帕克(Pankaj Parkar)

您还有,两个地方,这导致json解析错误

"age": 2, //<--here
"age": 1, //<--here

您应该删除无效,JSON响应及确保所有的propertiesstrings是包装内"(双引号)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

AngularJS SyntaxError:意外令牌

AngularJS Uncaught SyntaxError:意外令牌:

angularjs-SyntaxError:从服务器返回请求时出现意外令牌

JSON对象问题:未捕获的SyntaxError:意外的令牌

angularjs,加载本地json结果为“ SyntaxError:意外令牌'”

SyntaxError:意外令牌`<`-AngularJS应用程序无法正常工作

AngularJS服务继承问题

AngularJS服务问题

AngularJS $ http问题

$ http计时问题,AngularJS

Jinja Flask问题:Uncaught SyntaxError:意外令牌{在JSON.parse位置1的JSON中

SyntaxError:Object.parse(本机)AngularJS处出现意外令牌o

JsonP返回“未捕获的SyntaxError:意外的令牌:” AngularJS-routingnumbers.info

SyntaxError:Object.parse(native)(AngularJS)位置0处的JSON中的意外令牌<

Angularjs:SyntaxError:JSON中意外的令牌'位于JSON.parse的位置97

Angularjs返回问题以响应$ http

Chartjs 与 PHP 问题(意外令牌)

AngularJS访问令牌安全问题

在AngularJS中缓存HTTP“获取”服务响应?

Bazel + Angular产品服务器不起作用(“未捕获的SyntaxError:意外的令牌'<'”)

(更新解决方案)Express Web App服务抛出“ SyntaxError:意外令牌>”

vue js 服务问题 - 模块解析失败:意外令牌 (763:13)

SyntaxError:JSON位置0处出现意外的令牌C-Ionic 2 Http GET请求

从Netsuite到Heroku的JSON HTTP请求解析返回错误“ SyntaxError:意外的令牌p”

使用webpack-manifest-plugin获取错误“未捕获的SyntaxError:意外令牌<”

找不到require.js,请继续获取Uncaught SyntaxError:意外令牌'<'

在没有给我位置的情况下获取SyntaxError:意外令牌}

当我尝试从json获取html时,出现了未捕获到的SyntaxError:意外令牌)

AngularJS $ stateProvider和单例服务问题