I have worked on AngularJS and recently had an overview on AngularDart. I want to know what are all the benefits of using AngularDart over AngularJS and from a developer perspective how will it help me improve applications (as Dart is a JS pre-processor).
Sabine Hofmann
First of all you should know that Dart is a completely different language. Angular has been ported to Dart which is known as AngularDart. So, assuming you are familiar with Angular I am going to list some of the good features of AngularDart and compare both.
Dependency Injection :
As you may know AngularJS has a good (not great) DI system. So, the Angular team learned from this and created a better and powerful DI system in AngularDart. Unlike AngularJS, the DI in AngularDart doesn't check the parameter names while injecting dependencies. So, you can write something like this to inject a dependency:
Here, Dart will automatically instantiate
EmailClientand pass it to the constructor. But you know this is not possible in AngularJS. For a Java programmer, this is old and pretty straightforward.Components :
The directives API in AngularJS is complicated and difficult to use. This has been simplified in AngularDart and they also utilize Shadow DOM. Creating components is very simple in AngularDart. For example,
The above snippet creates a
RatingComponent. You provide various meta data about this component a simple@Componentannotation and some attributes. Now you can use this component as<rating/>in HTML views.See : How components work.
No Controllers and Scopes :
You will admit that controllers and scopes are one of the most confusing concepts for newbie Angular developers. So, in AngularDart controllers are deprecated in the favor of Components (We discussed above). You simply set instance variables in the components and refer them directly in the views. As a result there is no need of scopes anymore.
No Need for Apply and Digest :
When you mutate scope models outside Angular's context you need to manually call
$scope.$apply()so that the view can be updated. This has been eliminated thanks to Dart Zones. Even if you modify some variables outside Angular's context (REST API call, third party integrations etc) AngularDart will be able to know about these changes.There are many more features and improvements in AngularDart, but I just outlined the most important ones.
AngularDart 1.1 is pretty stable. If you love the Type System in Dart and want an improved Angular, there is no reason to stay away from AngularDart.
But you need to transpile your Dart code into JavaScript before deploying to the server. This is because of the obvious reason that browsers don't understand Dart. I don't think vendors like Mozilla, Safari, IE etc will provide Dart support out of the box. Google also clarified that they are not going to bundle Dart VM with Chrome.