Skip to content

fix(Ng1ViewDeclaration): Make controllerProvider IInjectable #3056

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
Oct 1, 2016
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/ng1/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export interface Ng1ViewDeclaration extends _ViewDeclaration {
* }
* ```
*/
controllerProvider?: Function;
controllerProvider?: IInjectable;

/**
* The scope variable name to use for resolve data.
Expand Down
16 changes: 15 additions & 1 deletion test/ng1/stateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ describe('state', function () {
foo: function() { return 'Foo'; }
}
})
.state('dynamicController', {
url: "/dynamicController/:type",
template: "a",
controllerProvider: ["$stateParams", function($stateParams) {
ctrlName = $stateParams.type + "Controller";
return ctrlName;
}]
})
.state('home.redirect', {
url: "redir",
onEnter: function($state) {
Expand Down Expand Up @@ -647,6 +655,12 @@ describe('state', function () {
expect(template).toEqual("AcmeFooTemplate");
}));

it('uses the controllerProvider to get controller dynamically', inject(function ($state, $q) {
$state.transitionTo('dynamicController', { type: "Acme" });
$q.flush();
expect(ctrlName).toEqual("AcmeController");
}));

it('updates the location #fragment, if specified', inject(function ($state, $q, $location) {
// html5mode disabled
locationProvider.html5Mode(false);
Expand Down Expand Up @@ -1076,7 +1090,7 @@ describe('state', function () {
var list = $state.get().sort(function(a, b) { return (a.name > b.name) - (b.name > a.name); });
var names = ['', 'A', 'B', 'C', 'D', 'DD', 'DDDD', 'E', 'F', 'H', 'HH', 'HHH', 'ISS2101', 'OPT', 'OPT.OPT2', 'RS', 'URLLESS',
'about', 'about.person', 'about.person.item', 'about.sidebar', 'about.sidebar.item',
'badParam', 'badParam2', 'dynamicTemplate', 'first', 'home', 'home.item', 'home.redirect',
'badParam', 'badParam2', 'dynamicController', 'dynamicTemplate', 'first', 'home', 'home.item', 'home.redirect',
'json', 'logA', 'logA.logB', 'logA.logB.logC', 'resolveFail', 'resolveTimeout',
'root', 'root.sub1', 'root.sub2', 'second'];

Expand Down
12 changes: 7 additions & 5 deletions test/ng1/viewSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {PathFactory} from "../../src/path/module";
import {ng1ViewsBuilder, ng1ViewConfigFactory} from "../../src/ng1/statebuilders/views";
import {ViewService} from "../../src/view/view";
import {StateMatcher, StateBuilder} from "../../src/state/module";

import {State} from "../../src/state/module";
import {Ng1StateDeclaration} from "../../src/ng1/interface";

describe('view', function() {
var scope, $compile, $injector, elem, $controllerProvider, $urlMatcherFactoryProvider;
Expand Down Expand Up @@ -55,14 +55,16 @@ describe('view', function() {
let state, path: PathNode[], ctrlExpression;
beforeEach(() => {
ctrlExpression = null;
state = register({
const stateDeclaration: Ng1StateDeclaration = {
name: "foo",
template: "test",
controllerProvider: function (/* $stateParams, */ foo) { // todo: reimplement localized $stateParams
controllerProvider: ["foo", function (/* $stateParams, */ foo) { // todo: reimplement localized $stateParams
ctrlExpression = /* $stateParams.type + */ foo + "Controller as foo";
return ctrlExpression;
}
});
}]
};

state = register(stateDeclaration);
let $view = new ViewService();
$view.viewConfigFactory("ng1", ng1ViewConfigFactory);

Expand Down