jac0117 jac0117 - 4 months ago 29
AngularJS Question

Angular - getting value from path

I have the following URL:


I added my route the following way:

.when('/sso/salesforce/:companyId', { ....

I'm trying to resolve the companyId from the URL, in this case

I'm injecting $location into a resolve function to resolve the company ID, but I'm not sure how to get it from $location.

gives me an object with a property 'companyId: true'
I don't need to know that is present, I need to get the actually value

How is this done in angular 1? I'm new to angular, not sure how.


You can inject and use $routeParams for this as below.

In the config,

$routeProvider.when('/sso/salesforce/:companyId', {
            templateUrl: '/sso/salesforce/' + $routeParams.companyId + '.html'

In the controller,

function RouteController($scope, $routeParams) {
        $scope.templateUrl = '/sso/salesforce/' + $routeParams.companyId + '.html';