【问题标题】:How to access data from JSON file though Angularjs $http get req?如何通过 Angularjs $http get req 从 JSON 文件中访问数据?
【发布时间】:2016-04-10 18:05:55
【问题描述】:

15.html

       <html>
       <meta charset="utf-8">
     <title>Angularjs htttp services</title>
      <script  src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js">                 

   </script>
   <script src="controller15.js"></script>
   </head>
    <body ng-app="mainApp">
      <div ng-controller="people">
      <ul>
  <h2> names and ages of the programmers</h2>
   <li ng-repeat="person in persons">
    {{ person.Name +':' +person.Age}}
   </li>
   </ul>
   </div>
  </body>
  </html>   

controller15.js

       var app=angular.module('mainApp',[]);
      app.controller('people', function($scope,$http)   
    {
     $http.get('database.json')
     .success(function(response)
    {
      $scope.person=response.records;
   });
   });

database.json 我存储信息的位置:

      {
      "records":[
       {
       "Name":"mehul","Age":"13"
       },
       {
       "Name":"ashok","Age":"23"
       },
       {
        "Name":"rajesh","Age":"44"
       }
       ]

 }

我已附上所有代码,请查看我的代码。我是 angularjs 的初学者;如果您向我推荐一个特定的材料或网站,那将是一件好事。

【问题讨论】:

  • 请尝试在这里使用简洁的标题:“嗨”和“请帮助我”因为它们无论如何都会被删掉,所以不需要。我已将您的代码分成几个部分:如果您可以确保为每个文件使用一个代码块,那么它的可读性会更多。谢谢。

标签: angularjs http get data-retrieval


【解决方案1】:

首先:不要使用缩小版的 Angular 来查看描述的错误 您的浏览器控制台。然后告诉我你看到了什么错误!

<script  src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js"> 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多