我一直想做的是显示ng-repeat的内容。问题是我不能使用双花括号{{ value }}
。
如果你还没有尝试过这个,请让我解释一下,如果你使用Laravel 5.2,这个表达式{{ value }}
将找到一个名为$value
的变量。显然,使用双花括号{{ value }}
,将不会引用ng-repeat
的内容,即使存在类似下面的表达式。
<tr ng-repeat="value in values"></tr>
所以,我通常依赖于ng-bind
,但ng-bind
似乎与ng-repeat
不一样。
我的代码看起来像这样。
<div ng-app="angularApp" ng-controller="TableController as tc">
<input type="text" ng-model="searchBox">
<table style="width:100%;">
<tr>
<th>Student ID</th>
<th>Name</th>
</tr>
<tr ng-repeat="student in students | filter:searchBox">
{{ student.name }}//This causes an error, indicating "Use of undefined constant student"
<td ng-bind="student.student_id"></td>
<td ng-bind="student.name"></td>
</tr>
</table>
</div>
<script type="text/javascript">
angular.module('angularApp')
.controller('TableController', function(){
this.data = {
students: [
@foreach($students as $student)
"{{ $student }}",
@endforeach
]
};
});
</script>
$students
是一个数组,包含名为student
的SQL对象。这来自Laravel的控制器功能。
你看到我做错了吗?任何建议将不胜感激!
答案 0 :(得分:1)
在你的剧本中:
<script type="text/javascript">
angular.module('angularApp', [], function($interpolateProvider) {
$interpolateProvider.startSymbol('[[');
$interpolateProvider.endSymbol(']]');
});
angular.controller('TableController', function(){
this.data = {
students: $students
};
});
在你的刀片中:
将{{ student.name }}
更改为[[ student.name ]]
答案 1 :(得分:1)
您可以在它之前添加@
https://laravel.com/docs/5.2/blade#displaying-data
由于许多JavaScript框架也使用&#34;卷曲&#34;大括号表示一个 给定的表达式应该在浏览器中显示,你可以使用@ 符号通知Blade渲染引擎表达式应该 保持不变。例如:
Laravel
您好,@ {{name}}。