Skip to content

Commit

Permalink
fix(ngView): IE8 regression due to expando on non-element nodes
Browse files Browse the repository at this point in the history
This fixes the "TypeError: Object doesn't support this property or method" error on IE8,
when view templates contain leading white-space.

Closes angular#3971
  • Loading branch information
IgorMinar authored and jamesdaily committed Sep 25, 2013
1 parent 381d0cc commit c24ed10
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ngRoute/directive/ngView.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ function ngViewFactory( $route, $anchorScroll, $compile, $controller,
currentScope[current.controllerAs] = controller;
}
clone.data('$ngControllerController', controller);
clone.contents().data('$ngControllerController', controller);
clone.children().data('$ngControllerController', controller);
}

link(currentScope);
Expand Down
9 changes: 6 additions & 3 deletions test/ngRoute/directive/ngViewSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ describe('ngView', function() {
});


it('should set $scope and $controllerController on the view', function() {
it('should set $scope and $controllerController on the view elements (except for non-element nodes)', function() {
function MyCtrl($scope) {
$scope.state = 'WORKS';
$scope.ctrl = this;
Expand All @@ -466,11 +466,14 @@ describe('ngView', function() {
});

inject(function($templateCache, $location, $rootScope, $route) {
$templateCache.put('tpl.html', [200, '<div>{{state}}</div>', {}]);
// in the template the white-space before the div is an intentional non-element node,
// a text might get wrapped into span so it's safer to just use white space
$templateCache.put('tpl.html', [200, ' \n <div>{{state}}</div>', {}]);

$location.url('/foo');
$rootScope.$digest();
expect(element.text()).toEqual('WORKS');
// using toMatch because in IE8+jquery the space doesn't get preserved. jquery bug?
expect(element.text()).toMatch(/\s*WORKS/);

var div = element.find('div');
expect(div.parent()[0].nodeName.toUpperCase()).toBeOneOf('NG:VIEW', 'VIEW');
Expand Down

0 comments on commit c24ed10

Please sign in to comment.