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
Asked
Active
Viewed 1,325 times
1
-
Have a look here : http://stackoverflow.com/questions/41318575/angular-2-typescript-input-output-or-input-output/41319049#41319049 – Milad Dec 30 '16 at 14:05
2 Answers
3
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>
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() {}
}

Igor Janković
- 5,494
- 6
- 32
- 46
0
Bindings in components template like [inputProp]="someValue"
are only allowed for @Input() inputProp;
or native properties of HTML elements with matching names.
I'm only guessing but 2 explanations come to my mind
more efficient code or code generation If properties need to be made explicit, this allows more efficient code
better support for tools This allows tools to check for errors in your code, provide autocompletion when writing templates, and probably more

Günter Zöchbauer
- 623,577
- 216
- 2,003
- 1,567