Skip to content

Commit

Permalink
feat($state): inject resolve params into controllerProvider
Browse files Browse the repository at this point in the history
Fixes #1131
  • Loading branch information
tjwallace authored and Sebastian Gebhardt committed Apr 27, 2015
1 parent 18d3241 commit 851f8e4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/state.js
Expand Up @@ -1394,7 +1394,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
promises.push($resolve.resolve(injectables, locals, dst.resolve, state).then(function (result) {
// References to the controller (only instantiated at link time)
if (isFunction(view.controllerProvider) || isArray(view.controllerProvider)) {
var injectLocals = angular.extend({}, injectables, locals);
var injectLocals = angular.extend({}, injectables, locals, result);
result.$$controller = $injector.invoke(view.controllerProvider, null, injectLocals);
} else {
result.$$controller = view.controller;
Expand Down
9 changes: 6 additions & 3 deletions test/stateSpec.js
Expand Up @@ -70,9 +70,12 @@ describe('state', function () {
.state('dynamicController', {
url: "/dynamic/:type",
template: "test",
controllerProvider: function($stateParams) {
ctrlName = $stateParams.type + "Controller";
controllerProvider: function($stateParams, foo) {
ctrlName = $stateParams.type + foo + "Controller";
return ctrlName;
},
resolve: {
foo: function() { return 'Foo'; }
}
})
.state('home.redirect', {
Expand Down Expand Up @@ -484,7 +487,7 @@ describe('state', function () {
it('uses the controllerProvider to get controller dynamically', inject(function ($state, $q) {
$state.transitionTo('dynamicController', { type: "Acme" });
$q.flush();
expect(ctrlName).toEqual("AcmeController");
expect(ctrlName).toEqual("AcmeFooController");
}));
});

Expand Down

0 comments on commit 851f8e4

Please sign in to comment.