Farzan Najipour
Farzan Najipour

Reputation: 2503

Angular - Get values from key value

I get data from URL and I have this data in result :

array: 2[
    1 => "LA"
    2 => "NY"
 ]

I want to show only value in List . Here is my code :

var app = angular.module('myApp', []);
        app.controller('MyCtrl', function($scope, $http) {
            $http.get('/getCities').
            success(function(data, status, headers, config) {
                $scope.cities = data;
            }).
            error(function(data, status, headers, config) {
                // log error
            });
        });

Is it the best way to show them?

<ul ng-repeat="(key, value) in cities">
  <li>  {{ value }} </td>
</ul>

EDITED : I edit my html to :

                            <ul ng-repeat="city in cities">
                                <li>  {{ city }} </li>
                            </ul>

Actually , I give this error : angular.min.js:117 Error: [ngRepeat:dupes]

Upvotes: 2

Views: 1335

Answers (1)

M. Junaid Salaat
M. Junaid Salaat

Reputation: 3783

This is an array. You don't need key value notations for repeatation. Just write

<ul ng-repeat="city in cities">
  <li>  {{ city }} </td>
</ul>

and Thats all.

Upvotes: 1

Related Questions