1

Angular http get call not working but without http dumping JSON its working fine. Any thoughts?

Data:

{
       "makes": [
          {
             "id": 200347864,
             "name": "AM General",
             "niceName": "am-general"
          },
{
             "id": 200347800,
             "name": "Toyota",
             "niceName": "toyota"
          }
            ]
        }


<body ng-controller="MakeListCtrl">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-2">
                    <!--Sidebar content-->
                    Search: <input ng-model="query">
                    Sort by:
                    <select ng-model="orderProp">
                      <option value="name">Alphabetical</option>
                      <option value="age">Newest</option>
                    </select>
                </div>
                <div class="col-md-10">
                    <ul class="phones">
                        <li ng-repeat="maker in makes">
                            <ul>
                                <li ng-repeat="make in maker.makes | filter:query | orderBy:orderProp">
                                    <p>{{make.name}}</p>
                                </li>
                            </ul>

                        </li>
                    </ul>
                </div>
            </div>
        </div>

    </body>


var phonecatApp = angular.module('phonecatApp', []);
    phonecatApp.controller('MakeListCtrl', ['$scope', '$http',
      function ($scope, $http) {
        $http.get('phones/phones.json').success(function(data) {
          $scope.makes = data;
          console.log(data);
        });

        $scope.orderProp = 'age';
      }]);
2
  • 1
    Did console is showing any error? Commented Sep 9, 2015 at 6:01
  • No errors but I can see data in console.log Commented Sep 9, 2015 at 13:06

1 Answer 1

3

Actually your controller itself is working fine. Its because of your ng-repeat code. I just made some modification and it works

<div class="col-md-10">
  <ul class="phones">
    <li ng-repeat="maker in makes.makes | filter:query | orderBy:orderProp">
         <p>{{maker.name}}</p>
    </li>
  </ul>
</div>

Here is the working Link

Sign up to request clarification or add additional context in comments.

3 Comments

can you provide the data ?
I have updated the answer and the link. Now it will work for your given data. Please check it
Your code is expecting array because its start with [. But my data starts with {. Still not working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.