0

If I have some value from angular $scope.id = '123', how can I use it in my jade template in node.js? I'd like to use it as part of the link.

p
   | {{id}} // It does work...

form(name="Remove", action="/cam/{{id}}_method=DELETE", method="post")
// ...but it doesn't
      button(type='submit')
           | ready
DiPix
  • 5,755
  • 15
  • 61
  • 108

3 Answers3

2

When using Jade you can use != operator for unescape HTML encoding.

form(name="Remove", action!="/cam/{{id}}_method=DELETE", method="post")

However this might lead to interpolation problems. Therefore, I would suggest you to have a function in a controller like so

$scope.form_url = function (id) {
  return '/cam/' + id + '_method=DELETE';
};

then this should do the trick:

form(name="Remove", action="{{form_url()}}", method="post")

Check these sources: nodejs, jade escape markup, AngularJS multiple expressions concatenating in interpolation with a URL

cch
  • 3,336
  • 8
  • 33
  • 61
0

Try:

form(name="Remove", action="'/cam/' + {{id}} + '_method=DELETE'", method="post")
mariocatch
  • 8,305
  • 8
  • 50
  • 71
0

Jade uses {} as an eval indicator when not prefixed by a pipe, so you'll need to use angular bindings that don't need this prefix. For your example I would create a controller function and pass it the ID and method. Here's an example:

script.
    angular.module('formapp', [])
        .controller('formctrl', function($scope, $http){
            $scope.formsubmit = function(id, method){
                $http({
                    method: method,
                    url: '/cam/' + id + '_method=DELETE'
                });
            };
        })
form(ng-controller="formctrl" name="Remove", ng-submit="formsubmit(id, 'post')")
  button(type='submit')
       | ready
myrcutio
  • 1,045
  • 9
  • 13