Symfony2的view使用的是TWIG模板,由于twig也是使用大括号“{{}}'来表示变量,因此和AngularJS冲突,可以利用symfony2的
二、my.js 文件内容
{% raw %} {%endraw %} 方法来解决这个问题,因为用
{% raw %} {% endraw%}
括起来的内容是不被twig执行的内容。举例如下:
一、index.html.twig 文件内容:
<!doctype html>
<html ng-app>
<head>
<meta charset="UTF-8" />
<script src="http://localhost:8000/web/js/angular-1.0.6/angular.min.js"></script>
<script src="http://localhost:8000/web/js/my.js"></script>
</head>
<body>
<div ng-controller="InvoiceCntl">
<b>Invoice:</b> hello {{ name }}!
<br><br>
<table>
<tr>
<td>Quantity</td>
<td>Cost</td>
</tr>
<tr>
<td><input type="integer" min="0" ng-model="qty" required></td>
<td><input type="number" ng-model="cost" required></td>
</tr>
</table>
<hr>
<b>Total:</b>{% raw %}{{qty * cost | currency}}{% endraw %}
</div>
</body>
</html>
二、my.js 文件内容
function InvoiceCntl($scope)
{
$scope.qty =1;
$scope.cost =19.95;
}