使用EJS将对象数组传递给ng-init

时间:2017-12-13 18:19:14

标签: angularjs node.js express ejs

我使用带有expressJS和EJS的nodeJs作为我的渲染引擎。在我的index.js中,我这样做了:

//index.js
app.get('/user/checklist/', function(req, res) {
var data = {
    checklist: [{
        title: "Announce your engagement",
        body: "Congratulations, you are engaged! Spread the word using #JustSaidYes or try these fun ways to announce your engagement."
    }]
}
     res.render('checklist', { data: data });    
});

我正在尝试将渲染方法中的对象数组传递给checklist.ejs中的ng-init,所以我这样做了:

 <!--checklist.ejs -->
<div ng-controller="CheckListCtrl" ng-init='items= <%- data.checklist %>'>
<div class="clearfix nservice-cancel-wrapper">
    <div ng-repeat="item in items">

    </div>
  </div>
</div>

我正在尝试使用对象数组初始化我的items变量,以便稍后我可以在程序中循环遍历它。但它不起作用,我得到的错误信息是:

[$parse:syntax] Syntax Error: Token 'Object' is unexpected, expecting []] at column 17 of the expression [items= [[object Object]]]

0 个答案:

没有答案