|
1 | 1 | describe('state', function () {
|
2 | 2 |
|
3 |
| - var stateProvider, locationProvider, templateParams; |
| 3 | + var stateProvider, locationProvider, templateParams, ctrlName; |
4 | 4 |
|
5 | 5 | beforeEach(module('ui.router', function($locationProvider) {
|
6 | 6 | locationProvider = $locationProvider;
|
@@ -59,6 +59,14 @@ describe('state', function () {
|
59 | 59 | return "/templates/" + params.item + ".html";
|
60 | 60 | }
|
61 | 61 | })
|
| 62 | + .state('dynamicController', { |
| 63 | + url: "/dynamic/:type", |
| 64 | + template: "test", |
| 65 | + controllerProvider: function($stateParams) { |
| 66 | + ctrlName = $stateParams.type + "Controller"; |
| 67 | + return ctrlName; |
| 68 | + } |
| 69 | + }) |
62 | 70 | .state('home.redirect', {
|
63 | 71 | url: "redir",
|
64 | 72 | onEnter: function($state) {
|
@@ -382,6 +390,12 @@ describe('state', function () {
|
382 | 390 | var err = "Could not resolve '^.Z' from state 'DD'";
|
383 | 391 | expect(function() { $state.transitionTo("^.Z", null, { relative: $state.$current }); }).toThrow(err);
|
384 | 392 | }));
|
| 393 | + |
| 394 | + it('uses the controllerProvider to get controller dynamically', inject(function ($state, $q) { |
| 395 | + $state.transitionTo('dynamicController', { type: "Acme" }); |
| 396 | + $q.flush(); |
| 397 | + expect(ctrlName).toEqual("AcmeController"); |
| 398 | + })); |
385 | 399 | });
|
386 | 400 |
|
387 | 401 | describe('.go()', function () {
|
@@ -595,6 +609,7 @@ describe('state', function () {
|
595 | 609 | 'about.person.item',
|
596 | 610 | 'about.sidebar',
|
597 | 611 | 'about.sidebar.item',
|
| 612 | + 'dynamicController', |
598 | 613 | 'first',
|
599 | 614 | 'home',
|
600 | 615 | 'home.item',
|
|
0 commit comments