diff --git a/src/lib/icon/icon.ts b/src/lib/icon/icon.ts index fc69c274f326..531ff777788f 100644 --- a/src/lib/icon/icon.ts +++ b/src/lib/icon/icon.ts @@ -200,8 +200,8 @@ export class MatIcon extends _MatIconMixinBase implements OnChanges, OnInit, Can // Remove existing non-element child nodes and SVGs, and add the new SVG element. Note that // we can't use innerHTML, because IE will throw if the element has a data binding. - for (let i = 0; i < childCount; i++) { - const child = layoutElement.childNodes[i]; + while (childCount--) { // reverse loop + const child = layoutElement.childNodes[childCount]; // 1 corresponds to Node.ELEMENT_NODE. We remove all non-element nodes in order to get rid // of any loose text nodes, as well as any SVG elements in order to remove any old icons.