Search code examples
angularjsangularjs-routing

$routeProvide get the value in URL in the view


I have this :

$routeProvider
    .when('/Customer/:id?', {
        templateUrl: templatePath + 'Customer/Detail.html',
        controller: 'myAngularJsController',
        caseInsensitiveMatch: true
    })
    .otherwise({
        redirectTo: '/defaultroute'
    });

The URL is : http://localhost:39765/#/Customer/7

I'd like get the value (7) in my page Detail.html, in an angularJs variable, how can I do this ?

Thanks,


Solution

  • Inject $routeParams service into myAngularJsController controller and read param by key

    console.log($routeParams.id);