Thinker
Thinker

Reputation: 5356

Angularjs http trailing slash

My Django backend urls look like following:

url(r'^exercises/get_exercise/$', views.get_exercise_state_by_user_id),
url(r'^exercises/get_exercise/(?P<exerciseId>\d)/$', views.get_single_exercise_for_user_id),

I want to hit the second url from my angular controller. 'exerciseId' I want to add dynamically.

Following attempt did not work:

var exerciseType = Number($stateParams.exerciseId); //exerciseType values as obtained from $stateParams are 1,2,3,4,5,6,7 

$http.get("https://localhost:8000/api/exercises/get_exercise/?exerciseId=" + exerciseType)
.then(function(response){

--some action--
}

This one also:

var exerciseType = Number($stateParams.exerciseId); //exerciseType values as obtained from $stateParams are 1,2,3,4,5,6,7 

$http.get("https://localhost:8000/api/exercises/get_exercise/?exerciseId=" + exerciseType + "/")
.then(function(response){

--some action--
}

Coding exerciseId manually in the $http.get url as follows works correct, but that's not what I want.

var exerciseType = Number($stateParams.exerciseId); //exerciseType values as obtained from $stateParams are 1,2,3,4,5,6,7 

$http.get("https://localhost:8000/api/exercises/get_exercise/2/")
.then(function(response){

--some action--
}

I should be able to add it dynamically as shown above. How can that trailing slash be appended after 'exerciseType' in the url. Is there any clean way to achieve that?

Upvotes: 0

Views: 186

Answers (1)

Thinker
Thinker

Reputation: 5356

Alright I couldn't figure out a simple thing. The answer is:

var exerciseType = Number($stateParams.exerciseId); //exerciseType values as obtained from $stateParams are 1,2,3,4,5,6,7 

$http.get("https://localhost:8000/api/exercises/get_exercise/" + exerciseType + "/")
.then(function(response){

--some action--

}

This hits the correct url.

Upvotes: 1

Related Questions