HTML link with data method not working

I am trying to create a link in an AngularJS application view to send a DELETE data method.

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 

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 get the following message:

 Cannot GET /logout 

It seems to me that the data method is not working. Does anyone know what is going on?

Thanks, bye.

+5
source share
1 answer

I suppose you're used to using data-method with Rails. There is no such thing as data-method in AngularJS (or HTML).

My suggestion is to either write your own directive to send the deletion, or add an action to your controller and use ng-click instead.

+2
source

Source: https://habr.com/ru/post/1263663/


All Articles