我正在尝试在使用 Symfony 2.3 创建的项目中包含 angular.js。我使用控制器中的 json_encode 函数将结果数组转换为 json
function displayAction(){
$user= $this->getDoctrine()->getRepository('DemoBundle:Users');
$result = $user->findAll();
$res= json_encode($result);
$res->header->set('Content-Type', 'application/json');
return $this->render('DemoBundle:Demo:demoView.html.twig',array('results'=>$res));
}
在 ng-init 中初始化它,
<div ng-init= "result= {{results}}"></div>
<table>
<tr ng-repeat="res in result">
<td>[[res.id]]</td>
<td>[[res.username]]</td>
<td>[[res.password]]</td>
</tr>
</table>
但它给了我一个空的json数组。