2

My address bar url is

hostname/admin/Usergroup_controller/view_members/1

I am calling internally using angular js

hostname/admin/Usergroup_controller/get_view_members/1

Here last is id which is now 1 but can be change.

I want to pass that url in following code

$http.get(site_url + 'hostname/admin/Usergroup_controller/get_view_members/1').success(function (data) {}

How can I ???

Hope you understand

3
  • 2
    var id = 1; $http.get(site_url + 'hostname/admin/Usergroup_controller/get_view_members/' + id)..... Commented Mar 21, 2016 at 13:03
  • Can someone use Angular and be blocked by a problem like that ? Commented Mar 21, 2016 at 13:08
  • @VincentDecaux by a problem like what? Commented Mar 21, 2016 at 13:20

1 Answer 1

1

From your question, I understand that you want to include the 'id' in the browser url, like hostname/admin/Usergroup_controller/view_members/1 and thereby want to perform a GET request using that 'id' as in $http.get(site_url + 'hostname/admin/Usergroup_controller/get_view_members/1')

I am assuming that you are using $routeProvider (Angular Routing). Now that means that you need to tweak the .when(path, route) method to pass the dynamic 'id' in the browser's url. So, the .when(path, route) will be like .when('/Usergroup_controller/view_members/:id', templateUrl: 'viewMembers.html'); assuming viewMembers.html is the page you want to route to.

After, changing the .when(path, route) you will need to extract the value of :id from the browser's url. That will be done by using $routeParams in the controller of the routed page which in this case will be viewMembers.html. In the controller of viewMembers.html you need to extract the value of :id by writting this:

$scope.idEnteredInBrowserUrl=$routeParams.id;

Now, you will need to pass the value, $scope.idEnteredInBrowserUrl in the service from which you will be performing the $http.get() request. This can be done by creating a function in the service, say

var setIdEnteredInBrowserUrl = function (id) {
  $http.get(site_url +  'hostname/admin/Usergroup_controller/get_view_members/'+id).success(function    (data) {}}

Please note that the $http.get() is mentioned inside the setter function because you want the $http.get() to be called only after this method has been called and you have to :id value to append it to the GET request URL.

Call this method from the controller of the viewMembers.html and pass the extracted :id value, $scope.idEnteredInBrowserUrl to the service.

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.