The Angular team has released version 1.5, completing a major upgrade that brings 1.X developers closer to what they'll encounter in version 2.
In the announcement blog post, Pete Bacon Darwin says that the goal of this release was "to improve the upgrade path to Angular 2. In this release we have added features that will enable developers to write Angular 1 applications that are closer to the way that applications are structured in Angular 2."
The biggest move towards Angular 2 is the introduction of the new module.component()
. This new helper aims to eliminate the need for developers to write directives in the traditional directive definition object style. Those familiar with Angular 2 will notice the similarity. From the post, here's an example of how to define a new component:
myModule.component('myComponent', {
template: '<h1>Hello {{ $ctrl.getFullName() }}</h1>',
bindings: { firstName: '<', lastName: '<' },
controller: function() {
this.getFullName = function() {
return this.firstName + ' ' + this.lastName;
};
}
});
These new components can be used in some scenarios where developers previously would have created a directive or over-used a traditional controller. But, it's not a complete replacement for traditional directives. For example, components can't be used for DOM manipulation and all components have to be triggered with a custom HTML element; attribute directives are not supported. A component as defined above is used like this:
<my-component first-name="'Alan'" last-name="'Rickman'"></my-component>
The new component guide provides a more complete overview of the differences between classic directives and components.
- One-way bindings
- Lifecycle hooks
- Binding to required directives
- Multi-slot transclusion
- Default transclusion content
Developers on version 1.4 can read the migration guide to see what changes are required as version 1.5 has breaking changes.
This is expected to be the biggest release for the foreseeable future. Asked by InfoQ about how 1.X will proceed, Bacon Darwin said:
We haven't started planning the next release cycle for Angular 1. Since we are getting close to the GA release of Angular 2, we do not expect to be developing Angular 1 in any way that doesn't move it closer to Angular 2. If breaking changes are required in order to achieve this then you can expect a 1.6 release. In the meantime we are continuing to work on Angular 1.5.x with bug fixes and minor features that do not diverge from the aim of making it easier to upgrade to Angular 2.
The new component router is expected to be released later this week.