Components interactions
Naser Afsar

Components interactions

Angular components are the basic block codes for client web applications. They are the User Interface (UI) elements that communicate and operate on a web browser. There are several ways to pass data between components (parent, children and siblings). 

Angular components interactions:

  • Input data binding "@Input()"
  • EventEmitter "@Output()"
  • ViewChild "@ViewChild()"
  • Injectable service
  • Lifecycle Hooks and A local variable

I am going to create a parent and a child components using Angular CLI tool. I'll use the decorator @Input() and data binding for Parent to communicate with it's child component. 

Results:

When I run the application, this output is displayed: 

Parent component:

Child component:

1- The @input is used for the properties to assign a value.

For example: @Input("parent") parentName:string

2- Using the property in the selector of the child component.

For example: <app-child [parent]="parent"></app-child>

This code adds the parent component in the app component, which it is the root component, and the parent component, adds the child component in its template. It is a simple process using data binding and decorator @Input.

Sample code

I'll write about the decorator @output and EventEmitter with an example next time. bye

To view or add a comment, sign in

More articles by 🅽🅰🆂🅴🆁 ‘

  • A quick look at Widgets

    If you own an iPhone then installing iOS 14 opens the door for Widgets. This version now includes adding Widgets into…

  • Angular framework for your next enterprise project

    Some benefits of Angular framework for your next enterprise project 1- Using RxJS library, the reactive programming…

  • Little on Flux and Redux

    Five (5) minutes reading. I have been using JavaScript (JS) for many years in building applications.

  • Reactive Extensions for JavaScript

    I am sure you have heard of Reactive Extensions for JavaScript ( RxJS ) if you are familiar with Angular, EmberJS…

  • Angular 7 CLI

    The Angular framework is constantly evolving and improving fantastically. It has to do with the quick changes in…

    2 Comments
  • Generics basics

    Click here to play with codes Click her to play with interface codes If you use one of the programming languages like…

  • Parent listens for child event

    Angular @Output provides a way for a child component to emit events to its parent component with the help of…

  • Working with CORS request header

    JavaScript web programming is growing fast and it is getting better over the years. However the Cross-Origin Resource…

    2 Comments
  • Angular and threeJS

    Note: The raw dragon COLLADA file is more than 8 MB and Github may not have the bandwidth to show it. Please try…

  • VR view with threejs JavaScript API

    Demo: VR view of Waneka lake Codes:github JavaScript is a powerful tool for developing and implementing web apps…

Explore content categories