我具有以下DOM结构
<div #carousalElement> <div class="singleCaousalElement"> <a> <img [src]="carousalURL1" class="carousalImage"> </a> </div> <div class="singleCaousalElement"> <a> <img [src]="carousalURL2" class="carousalImage"> </a> </div> </div>我可以使用ViewChildren
@ViewChildren('carousalElement') carousalElements;问题::当我在#carousalElement div下动态添加新的div时,它没有显示在carousalElements数组下.
PROBLEM: When I dynamically add a new div under the #carousalElement div, it does not show up under the carousalElements array.
我缺少明显的东西吗?
推荐答案Angular无法识别Angular指令或API未添加的HTML.同样,如果<div>没有模板变量#carousalElement,则@ViewChildren('carousalElement')也将找不到它.
Angular doesn't recognize HTML not added by Angular directives or APIs. Also if the <div> doesn't have a template variable #carousalElement, @ViewChildren('carousalElement') won't find it.
模板变量需要静态添加到组件模板中.动态添加它们是没有意义的. Angular处理仅在编译模板期间特定于Angular的模板构造.
Template variables need to be added statically in the components template. Adding them dynamically is meaningless. Angular processes Angular-specific template constructs only during compilation of a template.
更多推荐
@ViewChildren不会使用动态添加的DOM元素进行更新
发布评论