【问题标题】:How to use ViewChildren with different children?如何将 ViewChildren 与不同的孩子一起使用?
【发布时间】:2019-08-20 13:37:29
【问题描述】:

如何为组件制作通用包装器?

我需要能够用我的包装器包装任何组件。

例如:

child.html

...
<h2>child<h2>
...

包装器.dart

...
<h1><child><child><h1>
...

结果html:

<h1><h2>child<h2><h1>

我找到了ViewChildren,但这里显示了静态组件,就我而言,我不知道谁会是孩子。

我该怎么做?你能举个例子吗?

【问题讨论】:

    标签: dart angular-dart dart-html


    【解决方案1】:

    为此,您需要使用 ng-content。 https://webdev.dartlang.org/angular/guide/lifecycle-hooks#content-projection

    例如:

    child.html

    <h2>child<h2>
    

    包装器.dart

    <h1><ng-content></ng-content><h1>
    

    父 html:

    <wrapper><child></child></wrapper>
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-21
    • 1970-01-01
    • 1970-01-01
    • 2020-04-10
    • 1970-01-01
    • 1970-01-01
    • 2017-05-24
    相关资源
    最近更新 更多