【问题标题】:HTML link with data-method isn't working带有数据方法的 HTML 链接不起作用
【发布时间】:2017-02-01 11:39:57
【问题描述】:

我试图在 AngularJS 应用程序的视图中创建一个链接,只是为了发送一个数据方法 DELETE。

我的路线:

app.delete('/logout', function(req, res) {
   req.session = null
   res.status(200)
   res.redirect('/')
})

我的 PugJS 模板:

a(ng-href='/logout', data-method='delete', data-confirm='Are you sure?', rel='nofollow')
          span(translate) Logout  

生成的 HTML:

<a ng-href="/logout" data-method="delete" data-confirm="Are you sure?" rel="nofollow" class="" href="/logout">
   <span translate="translate" class="ng-scope">
      <span class="ng-scope">Logout</span>
   </span>
</a>

但是当我点击链接时,我会收到以下消息:

Cannot GET /logout

在我看来,数据方法不起作用。有人知道发生了什么吗?

谢谢你。

【问题讨论】:

    标签: html angularjs pugjs


    【解决方案1】:

    我想你习惯于在 Rails 中使用data-method。在 AngularJS(或 HTML)中,没有 data-method 这样的东西。

    我的建议是编写您自己的指令来发送删除,或者在您的控制器中添加一个操作并改用ng-click

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-24
      • 2016-05-23
      相关资源
      最近更新 更多