【发布时间】:2015-08-29 07:46:48
【问题描述】:
我是 Symfony2 和 AngularJS 的新手。我正在尝试使用 json_encode 来显示我的数据库的内容。但它不起作用。这是我的控制器:
public function catalogonewAction()
{
$data = $this->getDoctrine()->getManager()
->getRepository('AcmeRetroBundle:Game')->findAll();
return $this->render('AcmeRetroBundle:Default:catalogonew.html.twig',
array('data' => json_encode($data)));}
这是我的 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 %}
还有我的 app.js:
angular.module('myApp1', []).
filter('sortData', function() {
alert('Hi');
return out;
});
当我刷新我的页面时,它会显示如下: T1 T2 {{data.nombreJuego}} {{data.description}}
怎么了?
【问题讨论】:
-
看起来 javascript 错误阻止了 angularjs 引导,检查控制台并添加错误输出
-
问问自己逐字的意思。混合 Angular 模板和 Twig 模板至少可以说是令人沮丧的。
-
好的。我修复它。我更改了控制器中的所有代码并逐字删除。我使用 InterpolateProvider。
标签: php html angularjs symfony