[英]HTML link with data-method isn't working
Im trying to create a link in a view of AngularJS application just to send a data-method DELETE. 我试图在AngularJS应用程序的视图中创建一个链接只是为了发送数据方法DELETE。
My route: 我的路线:
app.delete('/logout', function(req, res) {
req.session = null
res.status(200)
res.redirect('/')
})
My PugJS template: 我的PugJS模板:
a(ng-href='/logout', data-method='delete', data-confirm='Are you sure?', rel='nofollow')
span(translate) Logout
The HTML generated: 生成的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>
But when I follow the link I receive the follow message: 但是,当我按照链接时,我收到以下消息:
Cannot GET /logout
It's looks to me that the data-method isn`t working. 我认为数据方法不起作用。 Does some one know what is happening? 有人知道发生了什么吗?
Thanks for while. 谢谢你。
I suppose you are used to use data-method
with Rails. 我想你习惯使用Rails的data-method
。 In AngularJS (or HTML), there is no such thing as data-method
. 在AngularJS(或HTML)中,没有data-method
这样的东西。
My suggestion is to either write your own directive to send the delete, or to add an action in your controller and use ng-click
instead. 我的建议是编写自己的指令来发送删除,或者在控制器中添加一个动作并使用ng-click
代替。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.