0

I want to change angular url to /jobs/id. i wrote like below one. will this work?

$location.path("/JobHire/jobs/"+response.data.id);

how should i write route config? i configured like this

$routeProvider
            .when('/jobs/:id',{
                templateUrl:'partials/job.html'
            })
            .otherwise({
                redirectTo:'/'
            }); 

        $locationProvider.html5Mode(true);

Is this a correct way. How to retrieve those parameters inside a controller.

1

2 Answers 2

2

You need to use a controller.

$routeProvider
            .when('/jobs/:id',{
                templateUrl:'partials/job.html',
                controller: 'jobController'
            })
            .otherwise({
                redirectTo:'/'
            }); 

and inside the controller you need to do something like:

.controller(function($scope, $http, $location) {

    var my_id = $location.id;

    $http.get('some_API/jobs/' + my_id).success(function(data) {
      //do something width data;
    });

 });
Sign up to request clarification or add additional context in comments.

Comments

1

You will need to define a controller in your route config as

$routeProvider
            .when('/jobs/:id',{
                templateUrl:'partials/job.html',
                controller: 'somecontroller'
            })
            .otherwise({
                redirectTo:'/'
            }); 

app.controller([$scope,$routeParams], function($scope, $routeParams){
 var id = $routeParams.id;
});

This is how you can get the id from url.

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.