Why I Think Angular 2 Will Still Be Angular

Posted on by Tero Parviainen (@teropa)

Since the announcements of all the Angular 2.0 changes last week, the Internets have been hot with people voicing their concerns and criticisms over what the Angular team is doing. Many of these criticisms are perfectly valid, but there's also plenty of hyperbole and even some straight-up misinformation being spread around.

There's one particular meme making the rounds that I feel like addressing. That is the idea that Angular 2.0 is going to be a completely new framework that shouldn't even be called Angular. That somehow, all of the concepts and ideas behind Angular 1.x are going to just go away and that there's going to be no upgrade path.

I can see how one might get this impression. With the way the 2.0 updates were presented at ng-europe, it is easy to take away the idea that pretty much everything is going to change. But the thing is, when you dig just a bit deeper, this simply isn't the case.

The Core of Angular

To me, there are really three core ideas at the center of the Angular framework: Change detection, dependency injection, and an extensible DOM. There is absolutely nothing I've heard about 2.0 that suggests these core concepts are going to go away.

Now, the APIs by which we access this core are going to change. Some of them are going to change a lot. But the core concepts will remain.

As Brian Ford has pointed out, one thing that will hopefully make this API transition easier is that Angular already strives to minimize the API surface between the application and the framework: There are no special "classes" application components need to inherit and extend. Most of your application code consists of your own, free-form functions and objects, that you plug into the framework.

But there is also something else that I think we should keep in mind: Most of the changes announced for Angular 2.0 are evolutionary, and designed to streamline the patterns many of us are already using. Last week I wrote about favouring "components" instead of ng-controller - which is something I'm doing because it improves my 1.x code. Many others have discovered the same thing. The Angular team is responding to what the community is moving towards, by having the framework support that pattern directly and straightforwardly. At the same time, they are obsoleting the older, inferior pattern, which is something a major release should allow them to do.

Here's another, very simple example:

Killing $scope

Here's a directive, one that takes a list of people, in action:

index.html


The directive is defined in terms of its isolate bindings, link function, and template. The link function attaches a helper function on the scope for the template to use:

person_list.js
app.directive('personList', function() {
  return {
    scope: {
      list: '='
    },
    link: function($scope) {
      $scope.getPersonCount = function() {
        return $scope.list.length;
      };
    },
    templateUrl: 'person_list.html'
  };
});

The template outputs the person count and the list of people:

person_list.html

{{getPersonCount()}} people

  • {{person.name}}

Fairly standard stuff. Now, here's a slightly different version of the same thing, which binds the list on a directive controller instead:

person_list.js
app.directive('personList', function() {
  return {
    scope: {
      list: '='
    },
    controller: function() {
      this.getPersonCount = function() {
        return this.list.length;
      };
    },
    controllerAs: 'ctrl',
    bindToController: true,
    templateUrl: 'person_list.html'
  };
});

The template now also accesses the data through the controller:

index.html

{{ctrl.getPersonCount()}} people

  • {{person.name}}

See what I did there?

The $scope as an explicit API facility is not there anymore. There's just a controller. The scope is still doing its thing behind the scenes, but I, as an application developer, don't really see it.

Angular 2.0 is not removing data binding, nor the possibility to call functions from templates. It's just removing the scope API that delivers these features in 1.x. As this example shows, "removing $scope" doesn't have to be that dramatic, and you can even get a lot done in 1.x without ever touching scopes directly.

What It Boils Down To

Many of the changes announced for Angular 2, drastic as some of them may be, really seem to me to just be designed to address the shortcomings of 1.x while keeping the core that makes Angular Angular. Yes, the API changes will be backwards-incompatible. That tends to happen with major releases. But by no means will it be "a completely separate framework".

Know Your AngularJS Inside Out

Build Your Own AngularJS

Build Your Own AngularJS helps you understand everything there is to understand about AngularJS (1.x). By creating your very own implementation of AngularJS piece by piece, you gain deep insight into what makes this framework tick. Say goodbye to fixing problems by trial and error and hello to reasoning your way through them

eBook Available Now

comments powered by Disqus