Hosted 8th free workshop on Angular

On 8 April, I hosted free workshop on Angular in Gurgaon. 110-120 developers attended workshop. It was my eighth workshop on Angular in last 8 months across India.

image

We started at 10 AM and concluded at around 5 PM. In the workshop, we covered basics of the following topics:

  • Using Angular CLI to create Hello World Angular 4 application
  • Bootstrapping
  • Web pack and dynamic module loading
  • Component
  • Modules
  • Displaying Data
  • Interpolation
  • Property Binding
  • Event Binding
  • Two-way Binding
  • Nested Components
  • Components communication with Input and Output
  • Using Template Expression in Component Communication
  • Life cycle hooks
  • Pipes
  • Custom pipes
  • Forms
  • Validations in forms
  • Configuring Routes
  • Routes and Actions
  • Parameters to Routes
  • Activate a Route in Code
  • Child Routers
  • Services
  • DI hierarchy
  • Getting Data with http
  • Posting data to API with http
  • Observables
  • Using Ignite UI Grid in Angular application
  • Adding Ignite UI for Angular data charts in application

Every attendees were very much involved in the sessions, and event at the break out time, there were many questions.

image

Microsoft was kind enough to provide us space for the workshop along with tea/ coffee for the attendees. I also thank Infragistics for all the support.

image

I thank each one who attended the workshop and hope it was useful for them. My next workshop would be on June on JavaScript design patterns and RxJS.

Communication Between Components Using @Input() in Angular

In Angular 2 a component can share data and information with another component by passing data or events. A component can be used inside another component, thus creating a component hierarchy. The component being used inside another component is known as the child component and the enclosing component is known as the parent component. Components can communicate to each other in various ways, including:

  • Using @Input()
  • Using @Output()
  • Using Services
  • Parent component calling ViewChild
  • Parent interacting with child using a local variable

In this article, we will focus on how a child component can interact with a parent component using the @Input() property. We’ll also look into intercepting the input message and logging changes in the input message.

image

Let us consider the components created in the listing below. We have created a component called AppChildComponent, which will be used inside another component.

We have also created another component called AppComponent. Inside AppComponent, we are using AppChildComponent:

In the above listings, AppComonent is using AppChildComponent, hence AppComponent is the parent component and AppChildComponent is the child component.

Passing data from parent component to child component

Let us start with passing data from the parent component to the child component. This can be done using the input property. @Input decorator or input properties are used to pass data from parent to child component. To do this, we’ll need to modify child AppChildComponent as shown in the listing below:

As you notice, we have modified the greetMessage property with the @Input() decorator. Also, we have implemented onInit, which will be used in demos later. So essentially, in the child component, we have decorated the greetMessage property with the @Input() decorator so that value of greetMessage property can be set from the parent component.

Next, let us modify the parent component AppComponent to pass data to the child component.

From the parent component, we are setting the value of the child component’s property greetMessage. To pass a value to the child component, we need to pass the child component property inside a square bracket and set its value to any property of parent component. We are passing the value of childmessage property from the parent component to the greetMessage property of the child component.

image

Intercept input from parent component in child component

We may have a requirement to intercept data passed from the parent component inside the child component. This can be done using getter and setter on the input property.

Let us say we wish to intercept an incoming message in the child component, and combine it with some string. To achieve this, we created a property called _greetmessage and using @Input() decorator creating getter and setter for _greetmessage property. In the getter, we’re intercepting the input from the parent component and combining it with the string. This can be done as shown in the next listing:

In the setter, we are manipulating incoming data from the parent component and appending some text to that. Keep in mind that the behavior of the parent component would not change whether we are intercepting the message or not. To explore it further, let us take another example and create a child component, which will display names passed from the parent. If the parent passes empty name value, then the child component will display some default name. To do this, we have modified the setter in the child component. In the setter, we are checking whether the name value is passed or not. If it is not passed or it is an empty string, the value of name would be assigned to a default value. The child component can be created as shown in the listing below:

Read full article on the Infragistics blog

Introduction to Angular Components

A component is a main building block of an Angular  application, and an application may have any number of components. We can consider a component a particular view of the application with its own logic and data.

In AngularJS 1.0, there was the concept of controllers, $Scope, and directives to bind data and logic to the view or to create custom elements on the view. In Angular , components perform all the tasks that were performed by controllers, scopes and directives. Data, logic and custom elements can all be created or added to the page using components in Angular .

Angular 2 applications are built around components, and we can consider component as a view with its own:

  • Template
  • Application Data
  • Logic
  • Styles, and more

Let’s Create Our First Component

Let us start with creating a very simple component to display “Hello World” on the page.

appcomponent.component.ts

 

 

There are mainly three steps to create a component

  1. Create a class and export it. This class will contain data and the logic.
  2. Decorate the class with @component metadata. Basically, metadata describes the component and sets the value for different properties, so that a TypeScript class can be used as an Angular  component.
  3. Import the required libraries and modules to create the component.

Three steps discussed above can be visualized in the diagram below:

image

As you can see, the Angular  component consists of:

  • A TypeScript Class to hold data and the logic;
  • HTML template and styles to display data in the app. It is also called as a view, which is seen by the user on the screen to interact.
  • Metadata which defines the behavior of a component. Component metadata is applied to the class using the @Component decorator. Different behavior of the component can be passed as properties of the object, which is and input parameter of the @Component decorator.

Read full article on the Infragistics blog

Exploring Attribute Directives in Angular

Attribute Directives are used to change the behavior, appearance or look of an element on a user input or via data from the service. Essentially, there are three types of directives in Angular:

  1. Component
  2. Structural directives
  3. Attribute directives

image

In this post, we will learn how to create Attribute Directives in Angular . So let’s say we want to change the background color of an element; in that case we would apply the attribute directive to the element.

Create first Attribute directive

Let’s start with creating the Attribute Directive. To do this, we need to create a class and decorate it with @directive decorators. A simple attribute directive to change the color of an element can be created as shown in the next listing:

Read full post on Infragistics blog

 

Recap: Angular 2 Road Trip – Coimbatore

Recap of Angular Road Trip – Ahmedabad

Recap of Angular 2 Road Trip – Gurgaon

Recap of Angular 2 Road Trip – Indore

image

To start with, I thank my employer Infragistics for all support in making these community events, specially Angular 2 road trip successful. We have awesome set of controls for your AngularJS 2, MVC, jQuery etc. application. I request to have a look and please download free trial of Ignite UI here

image

I would like to thank Biztalk 360 for organizing this event. Without their support, it was not possible.

On 15th October, I hosted fourth event of my Angular 2 Road Trip. Read more about Angular 2 here . This time, it was turn of city Coimbatore from South India to show the love for Angular 2 and there were around 90-100 developers attended the event.

image

We started at 11 am with Advanced JavaScript. In this three-hour session, we mainly focused on Objects and Prototypes. At the end of two hours of JavaScript, we came up with below diagram.

image

After JavaScript session , we took the lunch break. And after lunch, we started Angular 2. It was a mixed corwd so, we started slwowly and then moved to advanced topcis of Angular 2.

image

In three hours, we covered following topics in Angular 2,

  • Setting up development environment in VS Code
  • Understanding Bootstrapping
  • Understanding Modules
  • Understanding Components
  • Creating first component
  • Creating Service
  • understanding Routing
  • Performing CRUD operations using http
  • Forms and user input validation
  • Routing

I was very motivated and inspired to do better seeing participations and passion of the people. I must thank each attendee for their support in successfully execution of the event.

image

I would like to thank each attendees and team Biztalk 360 for organizing and making this event successful.

image

Last but not least I would like to thank following inspiring people for their support in making Angular 2 road trip successful.

Brad Green,

Dan Wahlin,

Glenn Block

Geard Sans,

Jaosn Beres ,

Todd Motto

image

Next destination is Bangalore. Thanks everyone.