# `@Input()` and `@Output()` properties `@Input()` and `@Output()` allow Angular to share data between the parent context and child directives or components. An `@Input()` property is writable while an `@Output()` property is observable.
See the for a working example containing the code snippets in this guide.
Consider this example of a child/parent relationship: ```html ``` Here, the `` selector, or child directive, is embedded within a ``, which serves as the child's context. `@Input()` and `@Output()` act as the API, or application programming interface, of the child component in that they allow the child to communicate with the parent. Think of `@Input()` and `@Output()` like ports or doorways—`@Input()` is the doorway into the component allowing data to flow in while `@Output()` is the doorway out of the component, allowing the child component to send data out.
#### `@Input()` and `@Output()` are independent Though `@Input()` and `@Output()` often appear together in apps, you can use them separately. If the nested component is such that it only needs to send data to its parent, you wouldn't need an `@Input()`, only an `@Output()`. The reverse is also true in that if the child only needs to receive data from the parent, you'd only need `@Input()`.
{@a input} ## How to use `@Input()` Use the `@Input()` decorator in a child component or directive to let Angular know that a property in that component can receive its value from its parent component. It helps to remember that the data flow is from the perspective of the child component. So an `@Input()` allows data to be input _into_ the child component from the parent component. To illustrate the use of `@Input()`, edit these parts of your app: * The child component class and template * The parent component class and template ### In the child To use the `@Input()` decorator in a child component class, first import `Input` and then decorate the property with `@Input()`: In this case, `@Input()` decorates the property item, which has a type of `string`, however, `@Input()` properties can have any type, such as `number`, `string`, `boolean`, or `object`. The value for `item` will come from the parent component, which the next section covers. Next, in the child component template, add the following: ### In the parent The next step is to bind the property in the parent component's template. In this example, the parent component template is `app.component.html`. First, use the child's selector, here ``, as a directive within the parent component template. Then, use [property binding](guide/property-binding) to bind the property in the child to the property of the parent. Next, in the parent component class, `app.component.ts`, designate a value for `currentItem`: With `@Input()`, Angular passes the value for `currentItem` to the child so that `item` renders as `Television`. The following diagram shows this structure: The target in the square brackets, `[]`, is the property you decorate with `@Input()` in the child component. The binding source, the part to the right of the equal sign, is the data that the parent component passes to the nested component. The key takeaway is that when binding to a child component's property in a parent component—that is, what's in square brackets—you must decorate the property with `@Input()` in the child component.
### `OnChanges` and `@Input()` To watch for changes on an `@Input()` property, use `OnChanges`, one of Angular's [lifecycle hooks](guide/lifecycle-hooks#onchanges). `OnChanges` is specifically designed to work with properties that have the `@Input()` decorator. See the [`OnChanges`](guide/lifecycle-hooks#onchanges) section of the [Lifecycle Hooks](guide/lifecycle-hooks) guide for more details and examples.
{@a output} ## How to use `@Output()` Use the `@Output()` decorator in the child component or directive to allow data to flow from the child _out_ to the parent. An `@Output()` property should normally be initialized to an Angular [`EventEmitter`](api/core/EventEmitter) with values flowing out of the component as [events](guide/event-binding). Just like with `@Input()`, you can use `@Output()` on a property of the child component but its type should be `EventEmitter`. `@Output()` marks a property in a child component as a doorway through which data can travel from the child to the parent. The child component then has to raise an event so the parent knows something has changed. To raise an event, `@Output()` works hand in hand with `EventEmitter`, which is a class in `@angular/core` that you use to emit custom events. When you use `@Output()`, edit these parts of your app: * The child component class and template * The parent component class and template The following example shows how to set up an `@Output()` in a child component that pushes data you enter in an HTML `` to an array in the parent component.
The HTML element `` and the Angular decorator `@Input()` are different. This documentation is about component communication in Angular as it pertains to `@Input()` and `@Output()`. For more information on the HTML element ``, see the [W3C Recommendation](https://www.w3.org/TR/html5/sec-forms.html#the-input-element).
## In the child This example features an `` where a user can enter a value and click a `