Angularjs remove() method is not working on IE11

2019-07-21 16:24发布

问题:

The following Angularjs remove() method is working fine in firefox. However when I use Internet Explorer 11 (IE 11), it is not working. I am getting the error, Object doesn't support property or method 'remove'

The following is my code. Any help please. You can even refer the plunker http://plnkr.co/edit/0XtT0f?p=preview, when you use IE11 'Remove Chart' won't function. I am using angulajs 1.2.16.

var chartDivs = angular.element(document.querySelector('.chartsDiv'))
var cntChartDivs = chartDivs.length;

if (cntChartDivs) {
    while (cntChartDivs > 0) {
        chartDivs[cntChartDivs - 1].remove();
        cntChartDivs = cntChartDivs - 1;
    }
}

回答1:

Doing chartDivs[cntChartDivs - 1] returns the raw DOM element. the remove() function is on the JQlite wrapper, so you just need to rewrap it.

angular.element(chartDivs[cntChartDivs - 1]).remove();

Alternatively you could just remove all of the charts in 'chartDivs' by doing:

chartDivs.remove();