Angular 4.2 release: General and Animation features

Angular 4.2 was released three weeks back itself.  The community aware of this release and upgraded in their many projects as well. But from my observation, the release specific features are still not used in most of the projects. Even though this release is not a major one there are many useful features to the Angular community. This release is mainly concentrated on Animation package if you look at the official change log.

The main features of Angular 4.2 release are

Generic features:

  • The Angular form inputs support validators such as min and max attributes
  • The ApplicationRef bootstrap method allows bootstrapping the component directly
  • Enhance i18n tooling such as MissingTranslationStrategy and location notes in translation files.
  • The first step on AOT component’s testing approach
  • Introduce flag to always compile the generated code.

Animation Features:

  • Animation options and input params
  • The animation() function for reusable animations
  • Query for inner elements within animations
  • Staggering multiple elements
  • Enabled queried elements
  • Routable animations
  • Programmatic animations using AnimationBuilder

Let’s dive into them one by one. First we will start with generic features in a quick tour.

Generic Features:

The general feature include  form validations, bootstrap a component explicitly, improving i18n tools, AOT support, checks for compilation and testing feature improvements.

Form validations:

The form components provided support for min and max properties along with other possible validations. For example, the input element with min and max validations would be as follows,

This feature is removed in later release (4.2.3) due to breaking changes. It may be ported back in next major releases.

Bootstrap component:

You can bootstrap Angular components directly by passing the element reference to the bootstrap method of ApplicationRef class. Please refer the API documentation for more details

Improvements to i18n tools:

If you are going to support internationalization and forgot to provide a translation, then the build will succeed with a warning that you might face issue with translations. You can configure the Angular compiler for different possibilities of “missing translation” behaviors:

  • Error
  • Warning (default)
  • Ignore

For example, the error configuration for JIT compile would be as follows

Please find the reference link for  more details.

Compiler options:

The compiler options can be controlled by the flag alwaysCompileGeneratedCode and will be turned on by default in the future releases.

Animation Features:

The animation feature is available from Angular 2.0 release itself.  The animation features moved to their separate package in Angular 4.0. The latest Angular 4.2 version introduces new and interesting animation features that  can be used for animations with input parameters, multiple elements, reusable animations and router-level animations.

Animation options and input params:

Angular 4.2 provides the way to configure or override options for each of the step-based animation methods. The examples for step-based animation methods such as trigger, transition, query, sequence and group available under animation package.

The animation options include delay and input parameters. Let us take an example of state transition animation with input parameters as below

Both time and opacity inputs will be replaced in the runtime.

Reusable animations:

The animations with input params is really a great feature but it can’t be reused across the components. If you can define the animations in an external files then it is easy to reuse. This can be achieved using animation() and useAnimation() API calls. Let us take a fade animation with input parameters in a separate fie as below.

Now the fadeAnimation can reused by importing in your component class,

This features make the input params configuration much powerful.

Handling inner elements and multiple elements  :

As we know that, the DOM structure has tree hierarchical format. There is a need to control the entire tree of elements animations. The query feature allows you to style elements in different ways as below

The query supports CSS selectors as well to get bunch of elements. Where stagger feature make sure that there will be some space between each step-based animation. For example, the below stagger allows 100ms time gap with an animation style

Control child animations:

If you provide animations for both parent and child elements then parent element might override the child animation. Otherwise both might animate at the same time. The animateChild() API call give more control to the parent node which decides when child needs to animate.

The child animation is called based on parent explicit call using animateChild().

Router Animations:

We observed that query’s useAnimation methods are designed to create inner animations at a convenient time with in a sequence. It is also good idea to create animations while navigating pages from one view to the other (i.e, While entering or leaving the page).

You can define the animations in routes configuration as below

The component class has to define the animation for different states

The template file needs to define the animation like any other animations

<!– component.html –>

Animation Builder:

The programmatic way of creating animations has more control the declarative approach of animations. The AnimationBuilder() API plays a significant role with more control by defining animations and play them in an order.


This release brings various generic features in different areas. But majorly it focused on animation features. We can say that this is an improved version for animation packages. As per semantic versioning Angular 4.3 need to released in few more days. I will post Angular 4.3 features in detail very soon. Cheers Geekos 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *