0 votes
in Angular by
How Can We Create Controllers and Pass Parameters in Angular UI Route?

1 Answer

0 votes
by

To create a controller, we need to use controller property of the state provider. To specify parameters, you can put the parameter name after the url. In the below code, you can see ‘Id’ parameter after the url and also you can see how validations are applied on these parameters using regex.

HTML
myApp.config(function ($stateProvider, $urlRouterProvider) {
    $stateProvider
        .state('State1', {
            url: '/SomeURL/{Id:[0-9]{4,4}}',
            template: '<b>asdsd</b>',
            controller: function ($scope, $stateParams) {
                alert($stateParams.Id);
            }
        });
...