0

I am building a small app using AngularJS and WebAPI.

Usecase: I am passing a string parameter from the drop-down ng-change event to a function called getcatdetails(selectedcategory) in controller.js and service.js calls WEBAPI.

Problem: When I add additional method in WEB API the code doesn't get fired. When I put the break point in controller and Service.js it looks fine but the call doesn't happen from Service to WEBAPI.

Here is the code..

HTML:

<select ng-model="selectedcategory" ng-options="item for item in catlist" ng-change="getcatdetails(selectedcategory)">
    <option value="">Select</option>
</select>

Controller.js

 $scope.getcatdetails = function (selectedcategory) {
    var catdetails = CategoryService.getcatdetails(selectedcategory);
 }

Service.js

this.getcatdetails= function (selectedcategory) {
    return $http.get("/api/ProductAPI/getcatdetails" + selectedcategory);
}

WEB API method

[Route("/api/ProductAPI/getcatdetails")]
public string getcatdetails(string selectedcategory)
{
    return selectedcategory;
}

Please help me ...i am totally struck


This is what I tried by I am still unable to call WEB API method..

Service.js

 this.getcatdetails = function () {
   return $http({ method: 'GET', url: 'api/productapi/getcatdetails', data: '"' + selectedcategory + '"' })
}


WEB API Method..

    [Route("api/ProductAPI/getcatdetails/{selectedcategory}")]
   public string getcatdetails(string  selectedcategory){

       return selectedcategory;

}

1 Answer 1

1

You can pass the category as part of the url, so chnage your method to be

[Route("api/ProductAPI/getcatdetails/{selectedcategory} ")]

public string getcatdetails(string selectedcategory)
{
    return selectedcategory;
}
Sign up to request clarification or add additional context in comments.

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.