Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.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
Angular2注入组件html模板未重置_Angular_Components_Inject - Fatal编程技术网

Angular2注入组件html模板未重置

Angular2注入组件html模板未重置,angular,components,inject,Angular,Components,Inject,当用户单击一个按钮时,会弹出一个模态,并将一个组件注入模态中。对于每个组件注入,是否注入了组件的新实例?如果是这样的话,有人知道如果我再次点击按钮,组件的另一个实例弹出到模式中,为什么注入组件的修改后的HTML不会被重置吗 模态 @Component({ selector: 'customize-modal-component', styleUrls: ['./modal.component.scss'], templateUrl: './modal.component.html'

当用户单击一个按钮时,会弹出一个模态,并将一个组件注入模态中。对于每个组件注入,是否注入了组件的新实例?如果是这样的话,有人知道如果我再次点击按钮,组件的另一个实例弹出到模式中,为什么注入组件的修改后的HTML不会被重置吗

模态

@Component({
  selector: 'customize-modal-component',
  styleUrls: ['./modal.component.scss'],
  templateUrl: './modal.component.html'
})

export class CustomizeModalComponent {
    private injectedComponet;

    showChildModal() {
        this.childModal.show();
    }

    injectComponent(component) {
        let componentFactory = this.componentFactoryResolver.resolveComponentFactory(component);
        this.injectedComponent = this.viewContainerRef.createComponent(componentFactory);
    }

    hideChildModal() {
        if(this.injectedComponent) this.injectedComponent.destroy();
        this.childModal.hide();
    }
}
@Component({
  selector: 'injected-component',
  template: '<div *ngIf="!validated">Successfully Validated {{validationId}}</div>'
})

export class InjectedComponent implements OnInit, OnDestroy {
    private validationId;
    private validated = false;

    modifyVariables(){
        validated = true
        validationId = 'ABYLO123';
    }
}
将组件注入模态中

@Component({
  selector: 'customize-modal-component',
  styleUrls: ['./modal.component.scss'],
  templateUrl: './modal.component.html'
})

export class CustomizeModalComponent {
    private injectedComponet;

    showChildModal() {
        this.childModal.show();
    }

    injectComponent(component) {
        let componentFactory = this.componentFactoryResolver.resolveComponentFactory(component);
        this.injectedComponent = this.viewContainerRef.createComponent(componentFactory);
    }

    hideChildModal() {
        if(this.injectedComponent) this.injectedComponent.destroy();
        this.childModal.hide();
    }
}
@Component({
  selector: 'injected-component',
  template: '<div *ngIf="!validated">Successfully Validated {{validationId}}</div>'
})

export class InjectedComponent implements OnInit, OnDestroy {
    private validationId;
    private validated = false;

    modifyVariables(){
        validated = true
        validationId = 'ABYLO123';
    }
}