Hacker News new | ask | show | jobs
by pramttl 3560 days ago
I have been using Angular 2 for 3 months now and so far have loved it (except for the breaking changes in RC series and updating each time). Glad 2.0.0 is here. Here are the few things I loved, amongst other interesting features:

1. Typescript awesomeness: You can write plain JS or give type hints in Typescript. Typescript is awesome, because it is a superset of Javascript and compiles to Javascript. (Typescript > ES6 > ES5)

2. Modular code: It is is much easier to manage Angular code as it grows (compared to AngularJS). Components could be made independently and reused within other components using component interaction [1] (@Input, @Output)

3. Template Directives: .html template directives are available unlike ReactJS. A ReactJS vs Angular2 blog post online [1] argued that that putting HTML in Javascript is better than putting Javascript in HTML. I'd argue that template directives like ngFor, ngIf, etc are much simpler to understand. Also, it is easier to collaborate with a designer/half-developer who knows some html/scss and doesn't know Javascript than working in ReactJS where every collaborator has to know JS. This way, it is also easier for someone to gradually learn the framework. For me, template directives are a big win. If someone wants to construct templates with plain JS, that is still possible in Angular.

4. @angular/router is better than AngularJS routing and we don't have to use a 3rd party library (like ui-router was more popular in AngularJS than the angularjs router)

One thing that I have found annoying is that: UI libraries for Angular. Example: material2 (currently at alpha.8) [3] are not complete yet and lack several useful components. This can be a problem if you are looking to quickly build a complete, good looking UI. Hopefully, now with Angular 2.0.0 out; Angular team could focus on quicker development of material2, so we have all the AngularJS Material UI goodness with Angular.

[1] https://angular.io/docs/ts/latest/cookbook/component-communi... [2] https://medium.freecodecamp.com/angular-2-versus-react-there... [3] https://github.com/angular/material2

5 comments

We've been using Angular 2 for about 6 months now. Having things deprecate several times like the routing engine was annoying but that's the cost of being on the cutting edge. The side benefit is that we learned a lot about the inner workings of Angular.

I agree with your annoyance with the UI libaries. It's been a PITA just to find a working datepicker. We eventually rolled our own starting with the source of an abandoned date picker project. Haha.

There is a working datepicker here: https://ng-bootstrap.github.io/#/components/datepicker

Source code here: https://github.com/ng-bootstrap/ng-bootstrap/tree/master/src...

Be aware, it is not perfect atm, especially around validation, but it is pretty much the only datepicker out there for ng2 in the open source world (not even Angular Material 2 has one).

It just got even better with alpha.5 (released just seconds ago :-)) - now you can have datepickers in popups: https://ng-bootstrap.github.io/#/components/datepicker
Angular Material 1 only got its date picker in Oct last year (0.11.2). Oh how we celebrated!
Have been making use of this component. This issue[0] regarding supporting floating labels is quite sad really.

[0] https://github.com/angular/material/issues/4233

This looks pretty nice. I definitely have not seen this one before. Thanks!
Just curious if you could speak to any of the performance / development time metrics? I.e. do you spend less time developing a component in ng2 vs. ng 1.x ? Do you get better performance with ng2 vs. 1.x etc?

I know it's supposed to be faster - I just am not finding people using this stuff in production seriously until now.

I don't want to clog up the angular group with these informal lines of questioning - obviously.

It's super easy to write a component in ng2. I feel like it's faster, but it's been about a year since I really used ng1.

My favorite thing about ng2 components over ng1 would be the annotations. One annotation turns my component into a component. It links the html template, sets up the services, injects the other components and directives it needs in one simple annotation. In ng1, I remember it being cumbersome to set everything up.

To use a component in your existing app. You create a new ts file. Add an annotation. Write the template inline or in another file. Reference that ts class in your other components. That's it!

I faced the same problem and found this one: http://www.primefaces.org/primeng/#/calendar

It basically uses the JQuery date picker and works quite well.

I tried that one out, but I feel like it choked on a regular javascript date when binding. I ended up skipping it.
We have been using Angular 2 seriously in the past month at my company.

There is a lot of roughness around currently when it came to upgrades during the RCs - Angular 2 was far from full-fledged even during the earlier ones, and has come a long way in the course of their development. Testing has a massive gap in documentation/articles on how to do it right. There are also some pains such as some (IMO somewhat poor) opinionation in the Angular router, especially when combining with server-side routing - had some battles integrating the Angular 2 app with the full server-side app for work, in large part due to hapi's major deficiencies when it comes to delegating routing to a frontend only application. Setting up can be daunting, although I got a large boost from using https://github.com/preboot/angular2-webpack, a great starter pack largely maintained by a member of the Angular docs team. Not all of the benefits are easy to tap into currently, such as the fairly recent AoT compilation, which lacks any plugin support for any build system such as Webpack currently. I intended to write one & open source it, but I was assured by a member of the Angular team that it was on the docket to complete. Documentation also needs a lot of work to be more developer friendly, I have found senior developers making easy mistakes with Angular 2 because they are not familiar with how to structure everything while having to produce on difficult story work. Testing is also a sore point, especially with the need for the karma shim to be produced for each app.

That said, Angular 2 is a phenomenal upgrade over Angular 1 in the ease of structuring apps. It also avoids incorrectly munging everything into components, avoids imperative logic to construct DOM/components, and imposes opinionation & more modern tooling such as the availability of observables to more correctly manage app state & app flow. It is fast, and much easier to tap into optimizations than Angular 1, where one had to be able to work close to the source code in order to understand everything one can and cannot do. It also offers the flexibility to do everything one can do with React, including server-side rendering (with the ability to do so on platforms such as PHP, Java, Node, and .Net in the pipeline), web workers, service workers, and multiplatform apps via React Native or NativeScript.

Awesome - thanks so much for this from a team running 1.3 in production (and looking now at moving to 2).

Just curious if you are indeed saying that the built-in router allows you to do EVERYTHING you could do with ui-router (nested states / targeted views etc)? I was planning on sticking with ui-router-ng2 when we kick over to angular 2.

How about testing? Was that difficult moving test suites over?

I didn't have to migrate tests over since I was started with a fresh project in Angular 2.

Angular Router does allow nested states: - https://angular.io/docs/ts/latest/guide/router.html - https://angular.io/docs/ts/latest/api/router/index/Router-cl...

I don't quite recall what "targetted views" mean?

I think targeted views means multiple <router-outlet>s, which it does appear to support:

> A template may hold exactly one unnamed <router-outlet>. The router supports multiple named outlets, a feature we'll cover in future.

About testing: e2e test will take almost 0 efforts to migrate, unit-tests will be rewritten completely (although your code too, so nothing wrong with it).
Should be noted that UI-router supports ng2 as well (and React!)
> 3. Template Directives: Good comparison react & angular
I'm holding out for Angular 2.0.0.0