Using ui.router, we have a controller for a state:
controller('widget', function($repository, $stateParams){
$scope.widget = $repository.get($stateParams.id);
})
registered with:
.state('widget',
controller: 'widget',
template: '/widgetTemplate.html'
We've come upon a case where we like to reuse this controller as part of a template:
<div ng-controller="widget" ng-include="/widgetTemplate.html"></div>
but there doesn't appear to be an easy way to inject a mocked $stateParams object with the proper ID. Something like:
<div ng-controller="widget" ng-inject="{$stateParams: {id: 1234}}" ng-include="/widgetTemplate.html"></div>
Outside of writing a custom directive that augments ng-controller or refactoring our code to make use of inherited scopes, are there any out-of-the-box ways to do this?
See Question&Answers more detail:os