Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 591
JonatasTeixeira Avatar asked Oct 29 '22 12:10

JonatasTeixeira


1 Answers

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.

like image 88
Beterraba Avatar answered Nov 15 '22 05:11

Beterraba