@ViewChildren不会使用动态添加的DOM元素进行更新

编程入门 行业动态 更新时间:2024-10-25 15:29:58
本文介绍了@ViewChildren不会使用动态添加的DOM元素进行更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我具有以下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元素进行更新

本文发布于:2023-11-13 12:12:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584325.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   动态   ViewChildren   DOM

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!