Skip to content

Commit 32f718a

Browse files
fix(viewService): Allow root ui-view to be wrapped in ng-if
Fixed an off-by-one error in viewService which caused the root ui-view to not be deregistered properly. Closes #3004
1 parent 5a12f92 commit 32f718a

File tree

3 files changed

+66
-6
lines changed

3 files changed

+66
-6
lines changed

src/view/view.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export class ViewService {
185185

186186
return () => {
187187
let idx = uiViews.indexOf(uiView);
188-
if (idx <= 0) {
188+
if (idx === -1) {
189189
trace.traceViewServiceUIViewEvent("Tried removing non-registered uiView", uiView);
190190
return;
191191
}

test/core/viewServiceSpec.ts

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/// <reference path='../../node_modules/@types/jasmine/index.d.ts' />
2+
3+
import {UIRouter} from "../../src/router";
4+
import {tree2Array} from "../testUtils.ts";
5+
import {StateRegistry} from "../../src/state/stateRegistry";
6+
import {ViewService} from "../../src/view/view";
7+
import {ActiveUIView} from "../../src/view/interface";
8+
9+
let router: UIRouter = null;
10+
let registry: StateRegistry = null;
11+
let $view: ViewService = null;
12+
let statetree = {
13+
A: {
14+
B: {
15+
C: {
16+
D: {
17+
18+
}
19+
}
20+
}
21+
}
22+
};
23+
24+
let count = 0;
25+
const makeUIView = (): ActiveUIView => ({
26+
$type: 'test',
27+
id: count++,
28+
name: '$default',
29+
fqn: '$default',
30+
config: null,
31+
creationContext: null,
32+
configUpdated: function() {}
33+
});
34+
35+
describe("View Service", () => {
36+
beforeEach(() => {
37+
router = new UIRouter();
38+
registry = router.stateRegistry;
39+
$view = router.viewService;
40+
tree2Array(statetree, true).forEach(state => registry.register(state));
41+
registry.stateQueue.autoFlush(router.stateService);
42+
});
43+
44+
describe('registerUIView', () => {
45+
it("should track a ui-view", () => {
46+
expect($view.available().length).toBe(0);
47+
$view.registerUIView(makeUIView());
48+
expect($view.available().length).toBe(1);
49+
});
50+
51+
it("should return a deregistration function", () => {
52+
expect($view.available().length).toBe(0);
53+
let deregistrationFn = $view.registerUIView(makeUIView());
54+
expect(typeof deregistrationFn).toBe('function');
55+
expect($view.available().length).toBe(1);
56+
deregistrationFn();
57+
expect($view.available().length).toBe(0);
58+
});
59+
});
60+
});

test/ng1/viewSpec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/// <reference path='../../typings/angularjs/angular.d.ts' />
2-
/// <reference path='../../typings/angularjs/angular-mocks.d.ts' />
3-
/// <reference path='../../typings/jasmine/jasmine.d.ts' />
4-
1+
/// <reference path='../../node_modules/@types/angular/index.d.ts' />
2+
/// <reference path='../../node_modules/@types/angular-mocks/index.d.ts' />
3+
/// <reference path='../../node_modules/@types/jasmine/index.d.ts' />
4+
import * as angular from "angular";
55
var module = angular.mock.module;
66

77
import {inherit, extend, tail} from "../../src/common/common";
@@ -52,7 +52,7 @@ describe('view', function() {
5252
}));
5353

5454
describe('controller handling', function() {
55-
let state, path, ctrlExpression;
55+
let state, path: PathNode[], ctrlExpression;
5656
beforeEach(() => {
5757
ctrlExpression = null;
5858
state = register({

0 commit comments

Comments
 (0)