事件绑定和属性绑定有什么区别? [英] what is the difference between event binding and property binding?

查看:68
本文介绍了事件绑定和属性绑定有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在角度2的体系结构中,有两个术语:事件绑定和属性绑定.它们之间有什么区别?

In the architecture of angular 2 there are two terms Event binding and Property binding. What is the difference between them?

推荐答案

属性绑定-

如果您必须将值从父组件传递到子组件(无论该值是静态还是动态),我们必须使用 property binding ,这意味着我们使用以下方法发送该值属性上的属性,并通过使用 @Input 装饰器在子组件中接收它,例如属性绑定的示例,请参见-

Property binding -

In case you have to pass the value from parent component to child component (whether the value is static or dynamic) we have to use the property binding that mean by doing so we send the value using attribute on component and receive it in the child component by using @Input decorator for example of property binding see here -

<my-child [myProp]="myProp" />

事件绑定-

从父组件中捕获子事件/方法

Event Binding -

Catching the Child's Event/method from the parent component

无论何时我们必须在单击时触发某个事件或从子组件中触发其他事件并传递给父组件,我们都必须使用 Event Binding (事件绑定)参见下面的示例-

whenever we have to fire some event on click or something else from child component and pass to the parent component, we have to use Event Binding see here in the example below -

<my-child [myProp]="myProp" (onPropChange)="onPropChange($event)" />

这里有 onPropChange 作为输出事件绑定,我们可以使用EventEmitter触发该事件.

here we have onPropChange as output event binding, we can fire that event using EventEmitter.

有关更多详细信息,请参见此处

for more detail see here

这篇关于事件绑定和属性绑定有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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