javascript - Angularjs Get Json from url -


first time trying json data , show app using angularjs, not show data, code implemented

html

<div ng-app="myapp" ng-controller="customersctrl">   <table>      <td>{{ x.id }}</td>     <td>{{ x.title }}</td>  </table>  </div>  </body> </html> 

script

<script> var app = angular.module('myapp', []); app.controller('customersctrl', function($scope, $http) {     $http.get("http://example.com/api/get_page_index/")     .then(function (response) {$scope.names = response.data.pages;}); }); </script> 

json content url

 {       "status": "ok",       "pages": [         {           "id": 2,           "type": "page",           "slug": "sample-page",           "url": "http:\/\/example.com\/",           "status": "publish",           "title": "example page",           "content": "",           "excerpt": "",           "date": false,           "modified": "2016-08-09 17:28:01",           "comments": [],           "attachments": [],           }, 

you can this,

 <table>     <thead>       <tr>         <th ng-repeat="(header, value) in results[0]">           {{header}}         </th>       </tr>     </thead>     <tbody>       <tr ng-repeat="row in results">         <td ng-repeat="cell in row">           {{cell}}         </td>       </tr>     </tbody>   </table> 

working demo


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -