material icon indicating copy to clipboard operation
material copied to clipboard

mdSelect: "Failed to execute 'removeChild' on 'Node'" when moving to new route.

Open michaelbromley opened this issue 11 years ago • 4 comments

When there is an mdSelect, and one of the options triggers a route change (i.e. the select is used to navigate to new routes), the following error results:

Error: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.

Here is a Plunker demo of the issue: http://plnkr.co/edit/hAcv29c5gusO2SjP3ZF1?p=preview This example uses ngRoute as the router, but the issue also exists when using ui-router.

The error is caused by this line, which is attempting to remove the md-select-menu-container div upon selection. However in the case of a route change, the route change happens first, meaning the intended div is no longer there, resulting in the error.

It could potentially be a simple fix involving doing a check for existence before attempting to removeChild. I made the following change to my local copy which seems to have fixed it:

if (element[0].parentNode === opts.parent[0]) { // added this if statement
   opts.parent[0].removeChild(element[0]); // use browser to avoid $destroy event
}

michaelbromley avatar Apr 22 '15 09:04 michaelbromley

+1

sazonenka avatar Apr 23 '15 00:04 sazonenka

Thanks!

rschmukler avatar Apr 23 '15 18:04 rschmukler

Boom! Speedy service :+1: I can now consider myself a contributor to Angular Material in spirit at least ;)

michaelbromley avatar Apr 23 '15 19:04 michaelbromley

Haha if you'd opened a PR I'd have given you the authorship credit :P Next time. Wasn't sure if you had a CLA signed or I would have done it as well.

rschmukler avatar Apr 23 '15 19:04 rschmukler