简体   繁体   中英

from php url to json with angularjs

I am pretty much new to angularjs and onsenUI and have been stuck on figuring out how to display data from the php url into my page...

here is my code

controller.js

angular.module('app').controller('CardController',['$scope','$http', function($scope, $http) {
        $http.get('http://sth.sth.sth.php')
            .success(function(data, status, headers, config) {
              $scope.cards = data.cards;

      })
      .error(function(error, status, headers, config) {
         console.log(error);
         console.log("Error occured");
      });

card.html

<div ng-controller="CardController">
    <ul >
        <li ng-repeat="item in cards track by $index">
          {{cards.title}}
          {{cards.id}}
        </li>
      </ul>
  </div>

I will be more than thankful if someone chip me a way to figure it out. Thanks

Instead of cards its should be item -

    <li ng-repeat="item in cards track by $index">
      {{item.title}}
      {{item.id}}
    </li>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM