From 8fe5b1f27d7b0e0832c91e06e8db78974f4e1d07 Mon Sep 17 00:00:00 2001 From: Chris Thielen Date: Fri, 17 Mar 2017 15:38:33 -0500 Subject: [PATCH] fix(view): Allow targeting nested named ui-view by simple ui-view name Closes https://github.com/angular-ui/ui-router/issues/3355 --- src/directives/viewDirective.ts | 6 +++++- test/viewDirectiveSpec.ts | 26 ++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/directives/viewDirective.ts b/src/directives/viewDirective.ts index 17d8a5ac4..8706e0b6d 100644 --- a/src/directives/viewDirective.ts +++ b/src/directives/viewDirective.ts @@ -214,7 +214,11 @@ function $ViewDirective($view: ViewService, $animate: any, $uiViewScroll: any, $ config: null, // The ViewConfig loaded (from a state.views definition) configUpdated: configUpdatedCallback, // Called when the matching ViewConfig changes get creationContext() { // The context in which this ui-view "tag" was created - return parse('$cfg.viewDecl.$context')(inherited); + let fromParentTagConfig = parse('$cfg.viewDecl.$context')(inherited); + // Allow + // See https://github.com/angular-ui/ui-router/issues/3355 + let fromParentTag = parse('$uiView.creationContext')(inherited); + return fromParentTagConfig || fromParentTag; } }; diff --git a/test/viewDirectiveSpec.ts b/test/viewDirectiveSpec.ts index c1c345118..c583cfa1a 100644 --- a/test/viewDirectiveSpec.ts +++ b/test/viewDirectiveSpec.ts @@ -722,10 +722,11 @@ describe("UiView", function() { beforeEach(module(function($stateProvider) { $stateProvider .state('main', { abstract: true, views: { main: {} } }) - .state('main.home', { views: { content: { template: 'home.html' } } }); + .state('main.home', { views: { content: { template: 'HOME' } } }) + .state('test', { views: { 'nest': { template: 'TEST' } } }); })); - it("shouldn't puke on weird view setups", inject(function($compile, $rootScope, $q, $state) { + it("shouldn't puke on weird nested view setups", inject(function($compile, $rootScope, $q, $state) { $compile('
')($rootScope); $state.go('main.home'); @@ -733,6 +734,27 @@ describe("UiView", function() { expect($state.current.name).toBe('main.home'); })); + + // Test for https://github.com/angular-ui/ui-router/issues/3355 + it("should target weird nested view setups using the view's simple name", inject(function($compile, $rootScope, $q, $state) { + let tpl = ` +
+
+ MAIN-DEFAULT- +
+
+
+
+
+ `; + let el = $compile(tpl)($rootScope); + + $state.go('test'); + $q.flush(); + + expect($state.current.name).toBe('test'); + expect(el.text().replace(/\s*/g, "")).toBe('MAIN-DEFAULT-TEST'); + })); }); describe('uiView transclusion', function() {