php - json_encode doens't work in my Symfony2's controller -


i'm new in symfony2 , angularjs. i´m trying use json_encode show database's content. doens't work. controller:

public function catalogonewaction()  {   $data = $this->getdoctrine()->getmanager()     ->getrepository('acmeretrobundle:game')->findall();     return $this->render('acmeretrobundle:default:catalogonew.html.twig',      array('data' => json_encode($data)));} 

this html.twig:

{% verbatim %} <div ng-app="myapp1" ng-init="mydata = {{ list|raw }}"> <table id="sorteddata"> <tr><th>t1</th><th>t2</th></tr> <tr ng-repeat="data in mydata | filter:sortdata">  <td>{{data.nombrejuego}}</td>  <td>{{data.description}}</td>  </tr>  </table>  </div>  {% endverbatim %} 

and app.js:

angular.module('myapp1', []).  filter('sortdata', function() {   alert('hi');   return out;  }); 

when refresh page shown this: t1 t2 {{data.nombrejuego}} {{data.description}}

what wrong?

i don't pass data back-end anuglarjs that, it's common use ajax request retrieve data.

try pass data javascript variable affect object in angular scope :

     <script>            var list= {{ data }}       </script>           {% verbatim %}            <div ng-app="myapp1" ng-init="mydata = list">            <table id="sorteddata">             <tr><th>t1</th><th>t2</th></tr>             <tr ng-repeat="data in mydata | filter:sortdata">               <td>{{data.nombrejuego}}</td>               <td>{{data.description}}</td>             </tr>            </table>           </div>      {% endverbatim %} 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -