【问题标题】:Adding custom attributes to ejs template将自定义属性添加到 ejs 模板
【发布时间】:2015-07-01 21:46:37
【问题描述】:

我在我的nodejs项目中使用ejs模板引擎,我通过下面的代码输出了文本元素

<%- text_field_tag('empId', '', {id: 'empId', Class: 'some_class', type: 'text'}) %>

现在为了使用 AngularJs 的优势,我想添加 ng-model 属性,所以我修改了如下代码

<%- text_field_tag('empId', '', {id: 'empId', Class: 'some_class', type: 'text', ng-model: "empId"}) %>

但这以错误结束——如下所示

SyntaxError: Unexpected token - in /home/ubuntu/workspace/public/views/add.ejs while compiling ejs

让我知道我应该如何实现这一目标?

【问题讨论】:

  • @AntoineEsteve 答案是正确的。使用'ng-model': 'empId'
  • 我认为 AntoineEsteve 删除了他的答案,但那不起作用
  • 查看您对@AntoineEsteve 的评论,您使用'ng-model'='empId' 而不是'ng-model':'empId'
  • 是的,它可以工作——我的错误是我使用 = 而不是:谢谢 Aleksandr。我们能得到那个答案吗?
  • 等待 Antoine 取消删除他的回答,如果没有,您可以自行回答。

标签: angularjs node.js ejs


【解决方案1】:

ng-model 需要单引号

<%- text_field_tag('empId', '', {id: 'empId', Class: 'some_class', type: 'text', 'ng-model': "empId"}) %>

这行得通

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-08
    • 1970-01-01
    • 2013-09-04
    • 2016-07-02
    • 2016-05-23
    • 1970-01-01
    相关资源
    最近更新 更多