
Angular 2 – Best Practises - budacode
https://blog.budacode.com/2016/06/27/angular-2-best-practises/?utm_source=hackernews&utm_medium=social&utm_campaign=angular2-best-practises
======
Shicholas
I'm going to get flamed for this, but I deeply regret the hours I put into
learning Angular.

I'm still disappointed that Angular 2 is such a sharp departure from Angular 1
and certain aspects of Angular 2 development, e.g. the fact there is still
multiple CLIs, the fact that "compiling to Dart" is still a thing, and the
fact that it's still unreleased give me no confidence to build anything in
Angular. I can't help but feel that with any library, less is more, and that
Angular 2 is already trying to do way too much. IMO Angular 2 should be a
Typescript-only library with one CLI and one way to manage your files (among
other changes made in the name of simplicity).

All this being said, I hope I'm terribly terribly wrong, and Angular 2 becomes
the super-simple-way-to-create-great-UIs that the authors intended that the
whole community can follow along. This article however, made me ask myself if
that will ever happen.

~~~
JustSomeNobody
It has been given the enterprise treatment. Enterprise devs _love_ big.

~~~
yoz-y
Do they? I also share the same feeling as GP. On one of our projects we have
made the decision to use the Angular framework and I do regret that choice
now.

------
bigmanwalter
After having gone around the SPA framework circuit, I'm back to using jQuery,
routing with PathJS, and templating with Jade (compiled using a Browserify
transform). It's just so much simpler to understand. No magic, and I have yet
to run into any problems. If I needed more complex model stuff, maybe I would
throw in Backbone.

I know these tools don't keep your code organized, but it doesn't prevent you
from organizing it either. And I really do hate all the levels of indirection
the monolithic SPA frameworks seem to throw in your face.

PathJS: [https://github.com/mtrpcic/pathjs](https://github.com/mtrpcic/pathjs)

Jadeify:
[https://github.com/domenic/jadeify](https://github.com/domenic/jadeify)

~~~
yawn
I've done the same. In production, I've used jQuery, Dojo, and ExtJS. On side
projects, I've used React, Clojurescript, and Angular 1. I don't like any of
them. I'm back to using pjax.

~~~
bigmanwalter
pjax doesn't get enough love on HN :) Recently I got to use a pjax clone
called smoothstate which splits up the pjax change event in just the right
places to get fancy transitions going. Really enjoying it too!

Smoothstate: [https://github.com/miguel-
perez/smoothState.js](https://github.com/miguel-perez/smoothState.js)

You can see how i used it at [http://zviwaldman.com](http://zviwaldman.com)
when you click any link.

------
cies
Could someone tell me one-or-more reasons to choose Angular for a new project,
now that the React ecosystem is mature enough to compete with it?

As I feel that from a conceptual/architectural point of view Angular is simply
on a loosing path.

[https://www.google.com/trends/explore#q=angular%20tutorial%2...](https://www.google.com/trends/explore#q=angular%20tutorial%2C%20react%20tutorial)

~~~
chvid
My impression is that a lot of "mature" (aka boring old) companies like
Angular 1 and the sound of Angular 2 over React.

For a number of reasons:

\- In general Java and C# programmers like it.

\- It is made by Google (perceived as more "mature", business like) rather
than Facebook (young kids).

\- It takes a lot of inspiration from server side development with its
dependency injection and general terminology.

\- And TypeScript is very similar to Java and C#.

(The list is a slight caricature but I hope the general point is clear.)

~~~
fchopin
> My impression is that a lot of "mature" (aka boring old) companies like
> Angular 1 and the sound of Angular 2 over React.

React has been around for a while, but it is still only a library. Angular 1
and 2 are frameworks. Also Angular 2 is a complete rewrite and not even in
final release. I'm not sure how that is boring or old.

As with Angular 1, Angular 2 aims to be opinionated, so it should be clearer
how to do things than with React. Especially now with the move to components,
Angular should be easier do more with, without as much confusion. And Angular
2 is much faster, if you do it right, which was one of the reasons Angular 1
was left for React.

React is fine for what it is. It's somewhat "matured" for a few years and is
not a bad decision if you go with it.

I don't think that you should just jump on the latest JS bandwagon, but
Angular 2 is more than just "for mature companies" and "similar to Java and
C#".

Really, the only frustration we've had with Angular 2 so far has been that it
has been changing so quickly, but it's starting to settle down now.

~~~
chvid
The places I am referring to are not actually using Angular 2. They are using
Angular 1 but like "the sound" of Angular 2.

Where the sound is the promise of a better tomorrow without actually looking
at alternatives.

------
spriggan3
While I found ng1 useful, I'll never touch this one. I can see now how
dependency injection can be both a blessing and also a curse in some contexts.
I also can see how Typescript features can shape a codebase and ultimately
make it look like Enterprise Java, instead of making it easy to use and to
learn.

I also just don't like the over use of non standard features like decorators.
There is a chance they don't make it to the spec, what then ?

~~~
rahkiin
As is shown with the decorator transpiling in both typescript and babel, it
doesn't really matter if it never makes it to the spec: you can still use it
using a compiler. I use it in my own production software and it is a real
blessing when trying to use a more OO approach in a JS world

~~~
spriggan3
> it doesn't really matter if it never makes it to the spec

I does matter as there is difference between introducing type support in a
language and introducing features that completely are non standard. Now
imagine TC39 introduces a decorator syntax that is not compatible with
Typescript's implementation ( it happened in the past with previous Typescript
module syntax and the language had to break compatibility )

Angular 2 is completely based on the use of decorators to inject almost
anything. Sometimes the decorator definition itself is bigger than the class
using it.

~~~
joshuacc
> it happened in the past with previous Typescript module syntax and the
> language had to break compatibility

Hmm. I thought that they just deprecated the old syntax while maintaining
backwards compatibility.

------
Illniyar
Well there are 2 advantages to angular (1 or 2) over react:

1\. It has effortless two way binding, which makes apps that allow mutating
the same state from a lot of places easy and simple to make (though one could
argue harder to maintain)

2\. It uses a template rather then a precompiler (such as jsx) which has two
advatages- since its html it makes cooperating with designers and the design
process itself easier and it means you can use strings for modularity (for
example saving a templatr in the database etc.)

~~~
skrowl
3\. You can just learn / hire for Angular 2. You don't have to learn / hire
for React + insert 5 other pieces of the stack required to make a complete
app.

------
sjclemmy
I've been using ng2 for a few Ionic 2 Projects recently and its fantastic.
Rxjs is an absolute must - it allows amazingly precise code to manage
mutation. The way everything is a component is great. I can write a frontend
app in a couple of days using Ionic 2. I'm so productive.

Edit: Why the downvote?

~~~
dkobia
Yes! ng2 + typescript is phenomenal, and makes ionic2 a pleasure to use. What
you get for the amount of time you put in is much more satisfying than with
ng1. Fun!

------
MilnerRoute
For what it's worth, Google's engineering director for Angular has said that
Angular 1 was a framework -- "something you could just drop into a web page
and get going". Angular 2 was supposed to be a "platform of capabilities."

"We're still doing the framework, but we're improving our ability to handle
different languages. Our plan is to have versions that will work with many
server-side technologies, from Java to Python... We would like to work to make
Angular future-proof. As we have new releases for Angular, it would be nice if
we could give just an upgrade script, so on every release, it would be stress-
free."

[http://thenewstack.io/google-preps-angular-2-final-
release/](http://thenewstack.io/google-preps-angular-2-final-release/)

~~~
nojvek
I like the ambition there. Something as complex as angular will definitely
require updates. Let's hope they actually walk the talk.

------
jaimehrubiks
Can someone recommend me good resources to learn (start with) angular 2? I am
totally new, I am learning node after JS and after that, I would like to
introduce myself to angular.

I have some experience on JSF but I suppose it is completely different.

~~~
dhaya
Angular 2's own tutorial is a nice start:
[https://angular.io/docs/js/latest/tutorial/](https://angular.io/docs/js/latest/tutorial/)
.

~~~
buckbova
Am I supposed to bite the bullet and just use/learn typescript?

"This chapter is not yet available in JavaScript. We recommend reading the
TypeScript version."

~~~
robwormald
Honestly? Yes. We support ES5 but strongly recommend using Typescript with
Angular2. Do you use ES6? If so, you already know how to use Typescript.

------
josephtate
When an article about Angular is posted here, It seems standard practice to
ignore the article itself—in this case, a writeup of Angular 2 best practices.
Instead it becomes a discussion on React vs Angular, Angular 1 vs 2,
frameworks vs no frameworks, etc. I’m not sure how to fix this problem—and I
see it as a problem because the article bears discussion. But even with this
comment I’ve derailed the original poster’s intent. So: is there a similar
forum where Angular-oriented articles are posted and the starting assumption
is that Angular is, well, good?

------
sanmon3186
Not directly related but I would appreciate any thoughts on which angular
version one should go with, for a _new_ development (fairly large enterprise
project) at this point of time. How hard would it be to upgrade to version 2.0
if we start our early development on v1.5, assuming 2.0 is not ready for prime
time (or is it?)

~~~
knicholes
There's a way to bootstrap your angular 1 app with an upgrade module so that
you can have both running at the same time. There are ways to
upgrade/downgrade your services/components so that they can be used in either
Angular 1 or 2. I know Angular2 is planning a release that breaks its forms
API, so there may be more small breaks like that, so take that for what it's
worth when deciding to use Angular 2 or Angular 1 (or both, once 2 stabilizes
more for your enterprise app). It took me two hours to bootstrap my angular
1.5 app with the upgrade module, along with transpiling .ts files with my es6
JS. Be aware, though, that if you do use Typescript, your build system is
going to change, and you're going to have to figure out how to use a module
bundler (SystemJS or WebPack, probably).

It may get pretty confusing if you're not used to transpilation, too. For
example, when you want to instrument your code for code coverage for your unit
tests, you need to map that instrumented code and its results to your
typescript files and not the es5 transpiled version of your code to see which
lines are failing/not being run/whatever. There are good plugins, but there's
definitely some effort involved.

People on my team are using Angular2 in their own projects and are claiming
huge productivity gains. They love the relative simplicity and power.

------
jprince
Best Practice to Level Up: Don't make a whole new framework that is in no way
compatible with the prior framework and just label it the same expecting
people to use it.

