1

Here is the scenario, I have a "Get course" button in the page when i click of the button, i'm passing courseId, In getCourse() method am returning $scope.courseId; then i'm passing this variable in $http.post method. but when i debug in developer tool i'm not getting courseId value.

    $scope.getCourse= function(){ return $scope.courseId;}

    $http.post('js/description.json', $scope.courseId).success(function(data){       
             $scope.response = data;        
    })

if i pass static course id like below, i'm getting the course id, so please suggest how to pass dynamic value.

    $http.post('js/description.json', {'courseId':'Adobe'}).success(function(data){       
             $scope.response = data;        
    })

7
  • 1
    why dont you use 'js/description.json', {courseId:$scope.courseId} Commented Feb 21, 2014 at 12:10
  • that's fine, you can pass directly like $scope.courseId or {courseId:$scope.courseId} it doesn't matter, but i'm having issue only at the time of dynamic variable. Commented Feb 21, 2014 at 12:15
  • Could you explain further, what you mean by "dynamic"? Commented Feb 21, 2014 at 12:36
  • sure, assume i have this below link, on click of this link i need to pass the value of "Adobe" to server using $http.post, along with the json/serverlet url. <a ng-click="getCourse(Adobe)">Get Course</a> Commented Feb 21, 2014 at 12:40
  • could you set up plunker of code what you have tried Commented Feb 21, 2014 at 12:48

2 Answers 2

1

Assuming $scope.getCourse= function(){ return $scope.courseId;} returns the Course Id. You could use

$http.post('js/description.json', {courseId: $scope.getCourse()}).success(function(data){       
         $scope.response = data;        
})

However, if you are passing Course Id into the method that does the post, you use

$scope.getCourse = function(Id){ // Id is passed into function
    $http.post('js/description.json', {courseId: Id}).success(function(data){       
         $scope.response = data;        
    });
}
Sign up to request clarification or add additional context in comments.

2 Comments

Still no luck for me.
Thanks a lot ur method worked pretty fine, thanks once again.
1

It looks like you are just passing the string "Adobe" instead of the object that the service expects. Try:

$http.post('js/description.json', {courseId: $scope.courseId}).success(function(data){       
             $scope.response = data;        
    })

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.