-1

I need to make ajax request. I can do this:

var categoryId = 152;
var url = "/someurl/category/"+categoryId;
$http.get(url);

Is it possible to use binding with $http? Something like:

$http.get("/someurl/category/:categoryId", {categoryId: 152});
Sharikov Vladislav
  • 7,049
  • 9
  • 50
  • 87
  • Any constructive criticism is welcome – Sharikov Vladislav Sep 16 '14 at 12:00
  • I don't really understand why you need to accomplish this via binding when concatenation is already easily readable and works, but I've been using tim for a long time under much more complex conditions: https://github.com/premasagar/tim - it's about as lightweight as you can get for simple string templating. – Adam Jenkins Sep 16 '14 at 12:02
  • @Adam is some native method exist? – Sharikov Vladislav Sep 16 '14 at 19:15
  • You're dealing with a string, a primitive. Here (on the left) are a list of all it's native methods - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String. The `tim` library I pointed you to is a fancy implementation of the `replace` method. – Adam Jenkins Sep 16 '14 at 19:22

1 Answers1

0

Continuation from my comment:

Example with tim:

var url = tim("/someurl/category/{{categoryId}}",{categoryId:152});
$http.get(url);
Adam Jenkins
  • 51,445
  • 11
  • 72
  • 100