我调用角js中的数据抛出json而不是接收数据的原因?

时间:2014-09-23 07:05:45

标签: javascript json angularjs

我在json中调用数据但是我的数据没有收到,请你帮助我。

我是角度js的新人。

我的代码就是这个

Angular Code

var phonecatApp = angular.module('phonecatApp', []);

phonecatApp.controller('PhoneListCtrl', function ($scope, $http) {
  $http.get('data.json').success(function(data) {
    $scope.phones = data;
  });

  $scope.orderProp = 'age';
});

HTML代码

<!DOCTYPE html>
<html ng-app="phonecatApp">

  <head>
  <title>Hello i </title>
    <link rel="stylesheet" href="style.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"></script>
    <script src="script.js"></script>
  </head>

  <body ng-controller="PhoneListCtrl">
    <h1>Hello Plunker!</h1>
   <div>Filter By  <input type="text" ng-model="query" /> </div>
   <div>Order By <select ng-model="orderPop">
      <option> Chose One</option>
      <option value="name">Name</option>
      <option value="price">Price</option>
    </select></div>
    <ul>
        <li ng-repeat="phone in phones | filter:query | orderBy:orderPop ">
            {{phone.name}}
            <p>{{phone.snippet}}</p>
            <h2>Price {{phone.price | currency:"$"}}</h2></h2>
        </li>

    </ul>
    <h4>Total No of Phone {{phones.length}}</h4>
  </body>

</html>

Plunker Demo

1 个答案:

答案 0 :(得分:1)

你在json中错过了引号:

    [{
      "name": "Nokia X250",
      "snippet": "nice application ",
      "price": "260"
    }, {
      "name": "Moto G",
      "snippet": "nice oprationg ",
      "price": "252"
    }]

http://plnkr.co/edit/5N8pndfBNH1EwOnqw5pT?p=preview