Skip to content

Commit

Permalink
fix(uiView): Properly handle uiView within a ngIf
Browse files Browse the repository at this point in the history
Use the linking function element instead of the template element.

Closes angular-ui#857
  • Loading branch information
Cody Lundquist committed Feb 4, 2014
1 parent f17b587 commit 67098a7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/viewDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '',
Expand Down
28 changes: 26 additions & 2 deletions test/viewDirectiveSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('uiView', function () {
controller: function() {
this.someProperty = "value"
},
controllerAs: "vm",
controllerAs: "vm"
};

beforeEach(module(function ($stateProvider) {
Expand Down Expand Up @@ -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('<div ng-if="someBoolean"><ui-view></ui-view></div>')(scope));

scope.someBoolean = false;

$state.transitionTo(aState);
$q.flush();
if ($animate) $animate.flush();

// Verify there is no ui-view in the DOM
expect(elem.find('ui-view').length).toBe(0);

// Turn on the div that holds the ui-view
scope.$apply(function() {
scope.someBoolean = true;
});

if ($animate) $animate.flush();

// Verify that the ui-view is there and it has the correct content
expect(elem.find('ui-view').text()).toBe(aState.template);
}));
});

describe('autoscroll attribute', function () {
Expand Down Expand Up @@ -325,4 +349,4 @@ describe('uiView', function () {
}))
});

});
});

0 comments on commit 67098a7

Please sign in to comment.