简体   繁体   中英

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.

My route:

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

My PugJS template:

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

The HTML generated:

<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. In AngularJS (or HTML), there is no such thing as 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM