Skip to content

Allow resolve params to be injected into controllerProvider #1853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/state.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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