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 = `
+
+ `;
+ 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() {