Skip to content

Commit 3dbc4ab

Browse files
atscottAndrewKushnir
authored andcommitted
fix(ivy): get name directly from nativeNode (angular#32198)
nativeElement can return null so an error can occur when accessing nodeName from nativeElement. PR Close angular#32198
1 parent cfed0c0 commit 3dbc4ab

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

packages/core/src/debug/debug_node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class DebugElement__POST_R3__ extends DebugNode__POST_R3__ implements DebugEleme
247247
return this.nativeNode.nodeType == Node.ELEMENT_NODE ? this.nativeNode as Element : null;
248248
}
249249

250-
get name(): string { return this.nativeElement !.nodeName; }
250+
get name(): string { return this.nativeNode.nodeName; }
251251

252252
/**
253253
* Gets a map of property names to property values for an element.

packages/core/test/debug/debug_node_spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,4 +1018,22 @@ class TestCmptWithPropBindings {
10181018
});
10191019

10201020
});
1021+
1022+
it('should not error when accessing node name', () => {
1023+
@Component({template: ''})
1024+
class EmptyComponent {
1025+
}
1026+
1027+
const fixture = TestBed.configureTestingModule({declarations: [EmptyComponent]})
1028+
.createComponent(EmptyComponent);
1029+
let node = fixture.debugElement;
1030+
let superParentName = '';
1031+
// Traverse upwards, all the way to #document, which is not a
1032+
// Node.ELEMENT_NODE
1033+
while (node) {
1034+
superParentName = node.name;
1035+
node = node.parent !;
1036+
}
1037+
expect(superParentName).not.toEqual('');
1038+
});
10211039
}

0 commit comments

Comments
 (0)