From 42e6bf2e811a0969888da9d441c821a8ae6c8118 Mon Sep 17 00:00:00 2001 From: Jeff Wallace Date: Wed, 1 Apr 2015 15:33:43 -0700 Subject: [PATCH] bug(state): inject resolve params into controllerProvider Fixes #1131 --- src/state.js | 2 +- test/stateSpec.js | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/state.js b/src/state.js index 51c55ee63..29d303a52 100644 --- a/src/state.js +++ b/src/state.js @@ -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; diff --git a/test/stateSpec.js b/test/stateSpec.js index 6880fac49..fa778c3fe 100644 --- a/test/stateSpec.js +++ b/test/stateSpec.js @@ -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', { @@ -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"); })); });