1

I use Angular UI router and have defined the following state:

$stateProvider.state('objectDetails', {
  url: '/object/:type/:id',
  templateUrl: 'url/to/my/template.html',
  controllerProvider: function($stateParams) {
    capitalized = $stateParams.type.charAt(0).toUpperCase() + $stateParams.type.substr(1)
    return capitalized + 'DetailsController'
  }
});

When I enter the /object/flower/123 I expect the controller of the view to be FlowerDetailsController etc. It works.

Question is how to handle an error (invalid object type in an url). I.e. the WeedDetailsController does not exist and when I enter the /object/weed/123, the error is being thrown.

How the controller provider is supposed to notify UI router that it can not provide any controller for given params? I would expect the router to display $urlRouterProvider.otherwise path, which I specified with nice 404 error.

fracz
  • 20,536
  • 18
  • 103
  • 149
  • What about [checking if the controller exists](http://stackoverflow.com/a/19737880/1800245) - if not providing a controller where you handle this error? – naeramarth7 Sep 26 '14 at 11:11

0 Answers0