0

So I have a php var named $output which when done echo json_encode($output) prints like following:

[{
    "title": null
}, {
    "title": "a b c"
}, {
    "title": "d e f"
}, {
    "title": "d f g"
}, {
    "title": "f g d"
}]

WHICH I BELIEVE IS CORRECT JSON

now I am using that output to load results via ng-init as it has to be on the same page so I use following code:

> <table ng-init="values =<?php echo json_encode($output); ?>">
>      <tr ng-repeat="value in values">
>          <td>{{value}}</td>
>      </tr>  </table>

it gives error as follows:

Error: [$parse:ueoe] http://errors.angularjs.org/1.4.9/$parse/ueoe?p0=values%20%3D%5B%7B

<table ng-init="values =[{" title":null},{"title":"a="" b="" c"}]"> 

and so on its a big array with lot of words in int. USING ABC IN PLACE OF ORIGNAL WORDS

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Anudeep Gupta
  • 39
  • 3
  • 11
  • you can't add php code to `html`, and when you add this inside angular directive (`ng-init`), it gives you parse error. [See this](https://stackoverflow.com/questions/11312316/how-do-i-add-php-code-file-to-html-html-files) – anoop Jun 09 '17 at 13:55
  • @anoop yes I can its a .phtml extension file – Anudeep Gupta Jun 09 '17 at 13:57
  • can you reproduce your error\issue on any online editor for .phtml? – anoop Jun 09 '17 at 14:13

3 Answers3

0

try it:<table ng-init="values =[{\' title\':null},{\'title\':\'a=\"\" b=\"\" c\'}]">

0

You need to get data from your server with call $http. After your call, set variable from your $scope of your controller and use ng-repeat in this variable for display the result.

nevradub
  • 238
  • 1
  • 9
0

I found this working somehow.....I dont know how but might help someone

 var obj = <?php echo json_encode($output) ?>;
      app.controller('MaCtrl', ['$scope', '$window', function($scope, $window) {
  $scope.obj = $window.obj;

  $scope.getMember = function(id) {
    $scope.values = $scope.obj;
    console.log($scope.values);
  };
}]);

 <table ng-controller="MaCtrl" ng-init="getMember(id)">
     <tr ng-repeat="value in values">
         <td>{{value.title}}</td>
     </tr>
 </table>
Anudeep Gupta
  • 39
  • 3
  • 11