angular的@input vs viewchild用于将数据从父级发送到子级组件 [英] angular's @input vs viewchild for sending data from parent to child component

查看:67
本文介绍了angular的@input vs viewchild用于将数据从父级发送到子级组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经以一种形式多次实现了相同的组件.我必须将数据从父组件发送到子组件.我知道可以通过@input或viewchild来实现.一个使用另一个的性能问题是什么?我什么时候应该使用Viewchild或输入?

I have implemented a same component more than once in one of my forms. I have to send data from parent to child components. I know that it can be achieved with @input or with viewchild. what is the performance issue of using one over the other? when should i use viewchild or input?

推荐答案

使用@Input()时,每次更改ngOnChanges()都会被调用,并产生更多的噪音.

When you are using @Input(), for every change the ngOnChanges() will be called and causes more noise.

使用ViewChild()不会产生任何此类噪音.因此,更喜欢使用Viewchild而不是@Input()

Using ViewChild() will not create any such noise. So, prefer using Viewchild over @Input()

这篇关于angular的@input vs viewchild用于将数据从父级发送到子级组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆