diff --git a/src/viewDirective.js b/src/viewDirective.js index 6e0813ad0..f19884cb5 100644 --- a/src/viewDirective.js +++ b/src/viewDirective.js @@ -70,16 +70,16 @@ function $ViewDirective( $state, $compile, $controller, $injector, $ui var directive = { restrict: 'ECA', - compile: function (element, attrs) { - var initial = element.html(), + compile: function (tElement, attrs) { + var initial = tElement.html(), isDefault = true, - anchor = angular.element($document[0].createComment(' ui-view-anchor ')), - parentEl = element.parent(); + anchor = angular.element($document[0].createComment(' ui-view-anchor ')); - element.prepend(anchor); + tElement.prepend(anchor); - return function ($scope) { - var inherited = parentEl.inheritedData('$uiView'); + return function ($scope, element) { + var parentEl = element.parent(), + inherited = parentEl.inheritedData('$uiView'); var currentScope, currentEl, viewLocals, name = attrs[directive.name] || attrs.name || '', diff --git a/test/viewDirectiveSpec.js b/test/viewDirectiveSpec.js index 8e1cf17a7..b8d47fdfc 100644 --- a/test/viewDirectiveSpec.js +++ b/test/viewDirectiveSpec.js @@ -82,7 +82,7 @@ describe('uiView', function () { controller: function() { this.someProperty = "value" }, - controllerAs: "vm", + controllerAs: "vm" }; beforeEach(module(function ($stateProvider) { @@ -275,6 +275,30 @@ describe('uiView', function () { // verify if the initial view has been updated expect(elem.find('li').length).toBe(scope.items.length); })); + + // related to issue #857 + it('should handle ui-view inside ng-if', inject(function ($state, $q, $compile, $animate) { + elem.append($compile('