我试图在我的前端使用一个小的AngularJS,但是继续遇到从后端推送数据的问题。我的后端是带有Handlebars模板的Node.js / Express / Mongoose / Mongo。
我试图将一个数组传递给一个Angular $ scope变量,但是它仍然使用下面的意外结束表达式错误进行轰炸:
Error: [$parse:ueoe] http://errors.angularjs.org/1.4.6/$parse/ueoe?p0=posts%3D%7B
at Error (native)
at http://localhost:3000/js/vendor/angular/angular.min.js:6:416
at Object.s.peekToken (http://localhost:3000/js/vendor/angular/angular.min.js:209:514)
at Object.s.object (http://localhost:3000/js/vendor/angular/angular.min.js:208:336)
at Object.s.primary (http://localhost:3000/js/vendor/angular/angular.min.js:205:503)
at Object.s.unary (http://localhost:3000/js/vendor/angular/angular.min.js:205:342)
at Object.s.multiplicative (http://localhost:3000/js/vendor/angular/angular.min.js:205:88)
at Object.s.additive (http://localhost:3000/js/vendor/angular/angular.min.js:204:430)
at Object.s.relational (http://localhost:3000/js/vendor/angular/angular.min.js:204:265)
at Object.s.equality (http://localhost:3000/js/vendor/angular/angular.min.js:204:90) <div class="container ng-scope" ng-controller="infiniteScrollCtrl" ng-init="posts={" _id":"55fb04878dabb2842d3deaeb","title":"my="" sixth="" post"}>
这就是我的代码:
<div class="container" ng-controller="MyController" ng-init="posts={{{ data.posts }}}">
<div class="row" ng-repeat='post in posts'>
<div>
{[{ post.title }]};
</div>
</div>
Angular插值符号被重新配置为{[{以免与把手发生冲突。
app.config(function($interpolateProvider) {
$interpolateProvider.startSymbol('{[{');
$interpolateProvider.endSymbol('}]}');
});
这就是data.posts的样子:
{"_id":"55fb04878dabb2842d3deaeb","title":"My Test Post"}
非常感谢任何帮助!
答案 0 :(得分:0)
为什么[]
中有{[{ post.title }]};
?
应该是:
<div>
{{ post.title }};
</div>