0

I am new in Angular JS and I want to display a php array in ng-repeat. here is my html code,

<div ng-controller="clientList">
 <ul>
   <li ng-repeat="client in clients">
    <h2>{{client.job}}</h2>
   </li>
 </ul>
 <p>Total number of phones: {{clients.length}}</p>
</div>

Here is my Controller of Angular JS,

var anguApp = angular.module('anguApp', []);

anguApp.controller('clientList',function($scope,$http)
{

   $scope.clients=[];

   $http.get('customers.php').success(function (data, status) {
    $scope.clients = data;
    console.log(data);
   });
});

customers.php

<?php
$arr=['name'=>'David','job'=>'developer'];
header('Content-Type: application/json');
echo json_encode($arr);
?>

Console Log : enter image description here getting response in console finely. but not getting in browser. where is the error ?....

1
  • can you attach your console.log(data) result here ? Commented Mar 9, 2015 at 16:43

1 Answer 1

1

its looks like you are requesting an array with no objects from your server. try this in your html code:

<li ng-repeat="client in clients">
    <h2>{{client}}</h2>
</li>
Sign up to request clarification or add additional context in comments.

7 Comments

Hi Gubkin, getting output finely. But how can i print a specific value with key.
you can't... you are getting an array from your server like this: ['value1', 'value2', 'value3']. your php array need to look something like this: [{name: david}, {name: john}] so you can repeat it by key
from my little knowledge of php, try this: $named_array = array( "nome_array" => array( array( "foo" => "bar" ), array( "foo" => "baz" ) ) );
Not getting output. :(
hmm. not too experiened with php. maybe try like your array to be like this?: [{"name": 'john'}, {'name': 'david'}]. not sure if this will work, anyway just google it shouldn't be too difficult
|

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.