angular 2输入装饰器为什么需要? [英] angular 2 input decorator why it need?
问题描述
我学习Angular 2.我面临着将数据传输到父组件的组件的任务.在官方文档中编写时使用@输入.否,但我不明白为什么angular 2的开发者做到了这一点为什么?如果没有@ INPUT,为什么不进行转帐.为什么要添加@Input?在说明中的文档中对我来说还不清楚
I study Angular 2.I was faced with the task to transfer the data to the component of parent component.in Official documentation is written to use the @ input.No but I do not understand why the developers of angular 2 made it need?.Why would not have made a transfer without @ INPUT.Why add @Input?In documentation in explain it is not clear for me
推荐答案
要定义组件的输入,请使用@Input装饰器.
To define an input for a component, use the @Input decorator.
例如,组件需要一个用户参数来呈现有关该用户的信息:
For example component needs a user argument to render information about that user:
<user-profile [user]="currentUser"></user-profile>
因此,您需要向用户添加@Input绑定:
So, you need to add an @Input binding to user:
import { Component, Input } from '@angular/core';
@Component({
selector: 'user-profile',
template: '<div>{{user.name}}</div>'
})
export class UserProfile {
@Input() user;
constructor() {}
}
这篇关于angular 2输入装饰器为什么需要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!