Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 255e8c1

Browse files
committedSep 20, 2013
fix(ngView): IE8 regression due to expando on non-element nodes
This fixes the "TypeError: Object doesn't support this property or method" error on IE8, when view templates contain leading white-space. Closes #3971
1 parent 88317a2 commit 255e8c1

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed
 

‎src/ngRoute/directive/ngView.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ function ngViewFactory( $route, $anchorScroll, $compile, $controller,
223223
currentScope[current.controllerAs] = controller;
224224
}
225225
clone.data('$ngControllerController', controller);
226-
clone.contents().data('$ngControllerController', controller);
226+
clone.children().data('$ngControllerController', controller);
227227
}
228228

229229
link(currentScope);

‎test/ngRoute/directive/ngViewSpec.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ describe('ngView', function() {
455455
});
456456

457457

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

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

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

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

0 commit comments

Comments
 (0)