Skip to content

Conversation

@ashB100
Copy link
Contributor

@ashB100 ashB100 commented Jan 17, 2025

using firstChild selects comment nodes and therefore gives a console error when adding a class to it

Description

There is a slight difference in where Angular renders the comment node (ie, the anchor for the view container) slightly differently in the @if(){}@else{} syntax compared to the *ngIf(condition; else tpl) syntax.

That is, in the @else part, the first child is now the comment node which isn't the case with the explicit structural directive syntax.

LgFooterNavItemComponent wants to get hold of the a element or button element then add a css class to it, this.renderer.addClass(childEl, 'lg-footer-action');. The else part errors as the firstChild returns the comment node, and tries to add a class to the comment node .

Using the firstElementChild solves this issue, as it will gets the first element and not the nodes (comments and text). firstChild gets the first comment, text or element.

Fixes # (issue)

Requirements

Please briefly outline any requirements for the work which may aid the testing and review process.

Design link: (link to design or delete if not required)
Screenshot: (if appropriate provide a quick screen grab of the changes)

Checklist:

using firstChild selects comment nodes and therefore gives a console error when adding a class to it
@ashB100 ashB100 requested a review from a team as a code owner January 17, 2025 14:14
@elenagarrone elenagarrone merged commit e181fb2 into Legal-and-General:master Jan 20, 2025
3 checks passed
@github-actions
Copy link
Contributor

🎉 This PR is included in version 13.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants