【问题标题】:Problem for use dynamic components with ng-template [closed]使用带有 ng-template 的动态组件的问题 [关闭]
【发布时间】:2021-12-18 12:49:21
【问题描述】:

我有问题(我认为是上下文),将动态组件与 ng-template 一起使用。

https://stackblitz.com/edit/angular4-wlv9rj?file=app/guidelines/guidelines.component.ts

我不明白我做错了什么,但我认为这是 Hook 的问题。

【问题讨论】:

    标签: angular components ng-content


    【解决方案1】:

    您正在尝试在渲染#areaContainer 元素之前查询@ViewChild('areaContainer'),因为#guideline_1 模板尚未激活。这就是它未定义的原因。首先渲染#guideline_1模板,然后在里面你可以参考#areaContainer

    【讨论】:

    • 谢谢你现在我明白我的错误了。在查询 areaContainer 之前,如何确定我的 #guideline_1 已准备就绪?
    猜你喜欢
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-26
    • 2019-12-05
    • 2020-10-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多