How to pass an Array to AngularJS?

2
array (
  0 => 
  Pessoa::array (
      'nome' => 'Paulo',
      'idade' => 15,
    )


app.controller('meuCrtl', function ($scope, $http, $timeout) {
 $http.get('ajax/getPessoa.php').success(function(data){
 $scope.list = data;

...

I do not want the data to be visible in getPessoa.php. Is there any other way to pass my data (array) to AngularJS so that it is hidden?

    
asked by anonymous 28.04.2015 / 18:13

1 answer

1

You need to serialize the array as JSON, which is what Angular is expecting to receive:

<?php
$dados = array (
    array (
        'nome' => 'Paulo',
        'idade' => 15,
    ),
    array (
        'nome' => 'João',
        'idade' => 20,
    )
);

header('Content-Type: application/json');
echo json_encode($dados);
  

I do not want the data to be visible in getPessoa.php.

I do not know if I understood this part properly, but if you want the person to type the URL of this file in the browser, nothing will appear, no, it is not possible. If you prevent the browser from viewing the data, Angular will not be able to see them either.

    
10.07.2015 / 05:30