mdSelect: "Failed to execute 'removeChild' on 'Node'" when moving to new route. #2481
Description
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
}