错误错误:无法在ViewContainer中插入被破坏的视图

时间:2018-06-27 06:24:29

标签: javascript angular typescript rxjs observable

我已经通过配置应用程序设计了一个页面生成器,它可以正常工作并生成组件,并将其尽可能好地呈现在页面上。

但是当我尝试通过新配置呈现新页面时,当生成器服务在清洁页面后尝试在页面上呈现第一个组件时,我会收到此错误ERROR Error: Cannot insert a destroyed View in a ViewContainer!

页面配置从{{1}的pageConfigService的{​​{1}}到达,ngOnInit尝试呈现NemoContainerComponent时出现错误。

**更新**

更改路线后将生成页面,所有路由的基本组成部分均为pageGenerator,并且当路由更改时,WidgetContainerComponent被销毁并再次创建。

**更新**

这是NemoContainerComponent

NemoContainerComponent

NemoContainerComponent在这里:

@Component({
    selector: 'nemo-container',
    templateUrl: './nemo-container.component.html',
    encapsulation: ViewEncapsulation.None
})

export class NemoContainerComponent {

    private subscription: Subscription = new Subscription();

    @ViewChild(ChildReferenceDirective) childReference: ChildReferenceDirective;

    constructor(
        private pageGenerator: PageGeneratorService,
        private route: ActivatedRoute,
        private routeService: RouteService,
        private router: Router,
        private storeEngine: StoreEngineService,
        private pageConfigService: PageConfigService
    ) {
        this.subscription.add(route.params.subscribe((params) => {
            this.routeService.setRouteService = params;
        }));
        let activeRoute = router.url.split('/').join(' ');
        document.body.className += ' ' + activeRoute;
    }

    ngOnInit() {
        this.pageGenerator.containerRef = this.childReference.viewReference;

        this.subscription.add(this.pageConfigService
            .get(this.route.data['value'].page)
            .subscribe(data => {
                this.pageGenerator.renderNewPageByConfigurationFile(data.json)
            }));
    }

    ngOnDestroy() {
        this.subscription.unsubscribe();
    }
}

**更新**

角度包版本:4.4.6

**更新**

在此先感谢您的帮助:)

0 个答案:

没有答案