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

3
  • 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 Commented Jun 9, 2017 at 13:55
  • @anoop yes I can its a .phtml extension file Commented Jun 9, 2017 at 13:57
  • can you reproduce your error\issue on any online editor for .phtml? Commented Jun 9, 2017 at 14:13

3 Answers 3

0

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

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

1 Comment

<table ng-init="values =<?php echo json_encode($output); ?>"> IS the code Ebubekir How can I change it manually
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.

6 Comments

that is the case when we make request to a php file but here in this can I have php code and html on same page
Question is how to make sure that JSON is read correctly by angular or parsed correctly
Yes but you can't set variable angular from your $scope directly in html file or phtml file or cshtml, ... You need to use call $http for this.
ng-init is reading the value but not correctly. Its not an issue of making $http requests
|
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>

Comments

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.