簡體   English   中英

使用數據方法的HTML鏈接無效

[英]HTML link with data-method isn't working

我試圖在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

我認為數據方法不起作用。 有人知道發生了什么嗎?

謝謝你。

我想你習慣使用Rails的data-method 在AngularJS(或HTML)中,沒有data-method這樣的東西。

我的建議是編寫自己的指令來發送刪除,或者在控制器中添加一個動作並使用ng-click代替。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM