Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从DOM中删除组件_Javascript_Angular_Dom - Fatal编程技术网

Javascript 从DOM中删除组件

Javascript 从DOM中删除组件,javascript,angular,dom,Javascript,Angular,Dom,我有一个组件,可以动态地将组件推送到DOM。 然而,每当我推送一组新的组件时,我都需要从DOM中删除旧组件。角度上的一切(2.) 如果我删除一个组件,它会工作,但如果我尝试删除组件数组,它将不起作用。插入工作正常,但移除工作不正常。 找到下面的代码段 let resolvedInputs = ReflectiveInjector.resolve(inputProviders); let injector = ReflectiveInjector.fromResolvedProvider

我有一个组件,可以动态地将组件推送到DOM。 然而,每当我推送一组新的组件时,我都需要从DOM中删除旧组件。角度上的一切(2.)

如果我删除一个组件,它会工作,但如果我尝试删除组件数组,它将不起作用。插入工作正常,但移除工作不正常。 找到下面的代码段

let resolvedInputs = ReflectiveInjector.resolve(inputProviders);

    let injector = ReflectiveInjector.fromResolvedProviders(resolvedInputs, this.dynamicComponentContainer.parentInjector);

    for(let t of data){


        //create a factory out of the component we want to create
        let factory = this.resolver.resolveComponentFactory(t.component);


        //create the component using the factory and the injector
        var component = factory.create(injector);

        this.currentComponent.push(component);
        // Insert the component into the dom container
        this.dynamicComponentContainer.insert(component.hostView);



    }

    if (this.previousComponent) {

            for(let comp of this.previousComponent){
                comp.destroy();
            }
        }

    this.previousComponent = this.currentComponent;

有什么想法吗

您只需重新初始化此.currentComponent:

this.currentComponent=[]之前<代码>用于(让t个数据)


您只需重新初始化
此。currentComponent

this.currentComponent=[]之前<代码>用于(让t个数据)