r/javascript • • Dec 15 '15

Angular 2 Beta is now available

http://angularjs.blogspot.com/2015/12/angular-2-beta.html
140 Upvotes

88 comments sorted by

26

u/wreckedadvent Yavascript Dec 15 '15

Well, I'm glad they bothered to keep upgrade paths in mind. That was one of my biggest concerns from the 2.0 announcement.

ngForward looks especially interesting, particularly for those who are still stuck with IE8 support.

However, I don't think I'll see myself using angular 2.0 personally. After react, mithril, riot, etc. I just don't find the boilerplate you have to use with 2.0 very attractive.

1

u/meenie Dec 15 '15

Do you mean the decorators (@Component(), @RouteConfig(), etc)? I find it really easy to see the configuration of a component right at the top like that. Also the new DI stuff is pretty amazing.

7

u/wreckedadvent Yavascript Dec 15 '15

I mean in general. I commented on an angular 2.0 example not too long ago here in another comment about it if you'd like to know more about why I think it's boilerplate-y.

1

u/meenie Dec 15 '15

I understand where you are coming from. And writing code like that is not for everyone. To contrast your example with Mithril, I feel a lot more comfortable writing explicit code like Angular2, rather than trying to grok everything going on in that feature packed Mithril example. The thing with making something so explicit is that you can later add some more sugar to it and create even more conventions that you don't need all the boilerplate. You could easily write your own decorator which extends the @Component decorator to make all of that less boilerplate-y.

I was listening to a live video chat with the Angular2 team saying that one of their team members, Viktor, is working on something like that already. Making a "shorthand" version to write components where you'll need the implicit knowledge of what's going on.

As of alpha.43ish they automatically include the core directives now, so no need to provide them.

7

u/wreckedadvent Yavascript Dec 15 '15

That "feature packed" mithril example is just three function calls, one of which is Array#map. There's also nothing implicit about it; I am explicitly making the element and then calling the child component directly. I guess you could say the default export is implicit if you really wanted to, but it's standard ES6 modules to me.

However, I'm glad to hear they're taking steps to reduce the boiler plate. CORE_DIRECTIVES was such a huge code smell to me, I have no idea how they didn't catch that sooner.

4

u/joshmanders Full Snack Developer Dec 15 '15

I agree completely, and I've been watching things. To be honest, I'm leaning harder at going to React over Angular 2.

1

u/meenie Dec 15 '15

I was under the impression that your mithril example was analogues to the Angular2 example. The @Input and @Ouput setup the interaction for the component that is being created. So assumed that what you wrote did the same thing, which is why I thought it was more implicit than what it is. We both obviously prefer different things, which is cool :).

1

u/wreckedadvent Yavascript Dec 15 '15 edited Dec 15 '15

I should be more clear then. It is analogous; they would do the same thing, just in the ways that each framework prefers. The angular example happens to set up a lot more because that's what angular requires, but they would render HTML that achieves the same thing.

The angular example uses @Input and @Output to mark how the data binding occurs. However, Mithril doesn't do databinding - the second parameter I pass into m.component is all of the arguments that component takes (it becomes the second argument in that component's view function). That takes care of @Input, and @Output is handled simply by referencing javascript variables in scope.

This is no less explicit than the angular one, just I am consuming my component directly instead of through HTML templates. I can definitely see how it wouldn't be for everyone, as there are still people who don't want templates with the javascript - and of those who do, even less who are willing to drop JSX (or MSX in this case) and just use pure function calls.

0

u/[deleted] Dec 15 '15

[deleted]

17

u/cheese_wizard Dec 15 '15

After using typescript for the last year... I can't see going back. It has caught so many typos for me, and code completion makes things go so much faster.

3

u/kenman Dec 16 '15

Typos that a decent IDE (Webstorm) and/or build system (JSCS/JSHint) wouldn't have caught?

5

u/cheese_wizard Dec 16 '15

Sorry, didn't mean like spelling typos, more like static checking errors like calling a string function on a number or something like that.

1

u/ivosaurus Dec 16 '15

Visual Studio / Visual Studio Code

1

u/pyromagnium Dec 16 '15

+1 for Code

1

u/I-fuck-animals Dec 16 '15

Which an IDE like WebStorm catches too, so /u/kenman's question still stands.

1

u/urban_racoons_ Dec 16 '15

A little off topic, but what sort of IDE do you use for typescript that includes code completion?

3

u/[deleted] Dec 16 '15 edited Feb 11 '17

4#xML2xKT$G+F&qAXsf4zMTR!dGPI~)f6Jw6A&i-8m%W8.3[R.8[(#1FWx$4qTB)l833KV&(6>FBxoiEvG(3&6+ifGi

2

u/I-fuck-animals Dec 16 '15 edited Dec 16 '15

WebStorm has Typescript completion

It has "completion", period.

Quite a few bugs previously, I submitted many bug reports to Jetbrains, but as of the current version 11.0.2 it seems to work very reliably.

And by the way, WebStorm recognizes inline JSDoc type hints (in additon to all the normal JSDoc):

let /**string[]*/ a;

From now on this is an "array of strings" (I prefer the short notation over Array.<string>) - for the code inspections as well as for completion. If you want types, with WebStorm and an IDE and/or tools recognizing JSDoc type info you get them with regular Javascript.

2

u/x-skeww Dec 16 '15

WebStorm, VS Code, and Atom all provide a very similar experience when working with TS, because the plugins are all built on top of TS' services.

Dart's tooling works the same way. The heavy lifting is done by the SDK's analyzer which is used by all plugins.

New languages should definitely copy this concept. It's the most efficient way to get top-notch tooling into all kinds of editors and IDEs. It also makes it easier to keep those plugins in sync with language changes.

1

u/cheese_wizard Dec 16 '15

I use PHPStorm... WebStorm has it too.

11

u/wreckedadvent Yavascript Dec 15 '15

One of the nice things about typescript at least is you can "progressively type". That is, you can write vanilla ES2015 and then add in types at whatever rate you're comfortable. It's even somewhat common to write pure ES6 and then add types after the fact, so you can take advantage of the dynamic nature of javascript while developing, and then solidify the API after you're good with it.

4

u/[deleted] Dec 15 '15

Typescript is not a requirement to use Angular 2.0, you can still use ES2015.

0

u/[deleted] Dec 15 '15

[deleted]

4

u/newmanoz Dec 15 '15

no, not harder. Just remove types (you don't need to use them in TS) and you'll get (almost) vanilla es6. Initial code conversion is as easy as changing file extension from js to ts.

2

u/[deleted] Dec 16 '15

Javascript taking a back-seat to Typescript? You're joking, right? Typescript is overkill in many cases.

5

u/MonsieurBanana Dec 16 '15

I read that as javascript taking a back-seat to typescript on angular 2.

4

u/Markthethomas Dec 16 '15

anyone w/ lots of React experience have any thoughts on Angular 2? I haven't tried out web components before — really curious how the two models (ng2 vs react) compare

7

u/neb636 Dec 16 '15

More interested in Angular 1.5 than Angular 2 Beta...

8

u/Vheissu_ Dec 16 '15

Eh. It took them two years to release a beta. For a project with resources provided by Google, that just is not good enough in my opinion. I probably know a little more about the inner workings of how the Angular 2 project functioned than publicly meets the eye and let's just say that it was poorly managed for a long time which is the reason Rob Eisenberg left the team after only 7 months. They rewrote a few pieces of the framework from scratch more than once.

And while I commend the Angular 2 team on releasing a beta, they were beaten to the punch by Aurelia and ReactJS has swooped in and stolen the spotlight. Yes, lots of people are still using Angular 1.x, but anyone starting a new project in 2015 is not choosing to use Angular 1.x or Angular 2, let me tell you. These days the rage is all about React and Aurelia. Anyone who has used React will tell you that it is awesome, I have also used Vue.js as well and it is great.

They are way too late to market. Angular 1.x was a marvel for its time, but there are so many better frameworks and view component libraries out there that take it to the slaughter. While some aspects of Angular 2 have been simplified, they have fallen into the same old trap of over-engineering and making the learning curve either difficult or confusing... yet again. The new templating syntax is horrendous, those square and rounded brackets, not to mention the asterisks, what were they thinking?

The amount of boilerplate logic and code required to get a simple hello world application up and running is going to scare a lot of developers. I actually feel sorry for them, all that work and really nothing impressive to show for it in beta form.

2

u/blunatic Dec 21 '15

The amount of boilerplate logic and code required to get a simple hello world application up and running is going to scare a lot of developers.

This was my first thought after looking over the Angular 2 documentation for Hello World a bit. When a simple example of Hello World looks extremely verbose and complicated, that isn't a good sign.

I've really enjoyed working with Angular 1.3/1.4 in personal projects, but I'm in the process of scoping out which framework/library to use for a new project I'm on and I just can't see Angular 2 being the winning choice. Seems like React has a much better setup at this point.

0

u/[deleted] Dec 16 '15

[deleted]

1

u/xlr8__ Dec 16 '15

+1, they didn't need all that shit. I understand they want to appeal to .net and jee developers but they are still keeping the templating approach, which makes React defacto superior to anything AngularJS 2 can do.

22

u/griffonrl Dec 15 '15

Too late.

19

u/Doctuh Dec 15 '15

JavaScript Famework ADD. React has gained some traction and may....Ooooh shiny!

8

u/AshamedOfYou Dec 16 '15

is anyone jumping on the riot bandwagon? Aside from that blog post I haven't seen anything about it. I get that JS is changing quickly but in my mind things are settling down as tools get more mature.

1

u/vinnl Dec 16 '15

I wouldn't expect it to be the next big thing. If you look at things that got big in the past few years (first jQuery, then Angular, now React), they all brought a fairly radical new way of programming to the table. Riot only has, AFAICT, things with the level of impact of a different syntax.

The only thing presently available that I've heard of and see as having a small chance of becoming a game changer is Cycle.js, but then again, that might still be too similar to React.

0

u/[deleted] Dec 16 '15

[deleted]

4

u/jbscript Dec 16 '15 edited Dec 16 '15

That React example is broken (the event handlers aren't binding to this and it's putting <li> inside <li>) and it's not doing the same thing as the Riot version - here's a working version which is a better functionality match:

Todo.js

import React from 'react'

export default React.createClass({
  getInitialState() {
    return {items: []}
  },

  handleSubmit(e) {
    e.preventDefault()
    let input = e.target[0]
    this.setState({items: this.state.items.concat(input.value)})
    input.value = ''
  },

  render() {
    return <div>
      <h3>TODO</h3>
      <ul>
        {this.state.items.map((item, i) => <li key={i}>{item}</li>)}
      </ul>
      <form onSubmit={this.handleSubmit}>
        <input/>
        <button>Add #{this.state.items.length + 1}</button>
      </form>
    </div>
  }
})

index.js

import React from 'react'
import {render} from 'react-dom'
import Todo from './Todo'
render(<Todo/>, document.querySelector('#app')

From what I've played with of it Riot is a good pick for projects which don't need the power and flexibility which comes with building your UI in code - there's always Mithril.js if you want that functionality in a lighter package. Vue.js is also worth a look if you like Riot's style, as its build tools let you define each component in one file in a similar manner.

The great thing about component-based stuff taking off is that as long as the data flow is mostly top-down, it's not that onerous to try a chunk of your app out in another library/framework.

2

u/losvedir Dec 16 '15

For those following along at home, this also switches the React from ES2015 style to the original style of building components.

That's because React.createClass automatically binds the this for its callbacks, which is helpful since that's what you usually want, but also somewhat magical. I personally prefer the ES2015 way where you have to be more explicit:

class Todo extends React.Component {
  // ...
  render () {
    <form onSubmit={this.handleSubmit.bind(this)}>
  }

This way explicitly binds the handleSubmit function to use the component's this, so the function can do something like this.setState(). Alternatively, you can use ES2015's arrow function which bind's this for you:

class Todo extends React.Component {
  // ...
  render () {
    <form onSubmit={() => this.handleSubmit}>
  }

Kind of weird at first, but you get used to it and then it feels more "javascripty".

1

u/jbscript Dec 16 '15 edited Dec 16 '15

I switched it as I don't currently see any benefit from using the ES6 class syntax, you end up either having to do more work in a constructor, or recreating event handlers on each render.

I was starting to do this sort of thing when initially porting some components over:

class Todo extends Component {
  constructor(props) {
    super(props)
    this.handleSubmit = this.handleSubmit.bind(this)
  }
  // ...
}

It's a smell to me that people are enabling experimental features in Babel solely to make the syntax of equivalent components tolerable with React.Component, particularly for statics and methods bound to the instance.

1

u/losvedir Dec 16 '15

or recreating event handlers on each render

Ah, interesting, what do you mean by this?

Do you think long term react is moving towards ES6, though? I'm new to react, and was under the impression that that was the direction the project was headed, so have been getting used to the new syntax. Have they made statements either way about long term support of both syntaxes?

27

u/[deleted] Dec 15 '15

Too little too late. We already migrated a large production app from Angular 1.x to React.

15

u/[deleted] Dec 15 '15

This is exactly what happened to me, however I'm glad react is fucking great.

1

u/buttonkop666 Dec 16 '15

Really. I'd be interested to hear how React handled input sanitization, xss security, routing, service decorators, inversion of control/dependency injection, abstraction of browser globals to enable better unit testing, and maybe about 100 other things we're using in our Angular 1 app, because I haven't seen any of that stuff in the React docs.

4

u/[deleted] Dec 16 '15 edited Feb 11 '17

kt>;bSpMt-tXPVw,5[3EnA3HuLm+W<TT1<eb5lh0391:LuDWGpGz!<R62vHTa75>1hJ!4tZB1kmA.VeXJO76vX<.[licK3&N]mi;&Ke<Au+xF6X-ZEmHeQ3#K(WhdF+:FCNQ9].ZB4^TLeVqc>F<0T,9eMRn,X&PVT&1ro95)#vmx9GUzM)Xrp5!n!FoO>EE[a-Da>C&iytbh

3

u/[deleted] Dec 16 '15

Poor browser support from Auerlia. We are considering Vue.js

3

u/[deleted] Dec 16 '15 edited Feb 11 '17

&O+4$sg6k.M7&buM~h(gV3DS)(Snw2A655h!>tT$PiE>c*X%1w-~>E88JbM&X%TPL(B+28ApJPC+<23T[X,Qz1ER)>v+d57.]O8HAP#X)lcIT&T67Ru(TD3OQDs0NME5a:2i>rhuoDes8md:M8Vq!h5lGXrsKG)qXC(L[

2

u/[deleted] Dec 16 '15

1

u/[deleted] Dec 16 '15 edited Feb 11 '17

ToS6-3w49n;KO+nmDARNm7XfpC2mIEpkMV5eN4pw90)c(W4WaNevu[-J,3uq.WqTJ%ocQb[3WzupPKeg(0b[.030kJ-L#[EI-wQBi6LBux(fGdE6v(<19]6CT

0

u/[deleted] Dec 16 '15

[deleted]

3

u/[deleted] Dec 16 '15 edited Feb 11 '17

!+*eC.Phduz5Zz[QQ:.0mHUV,lkTycAisTB+>3Qk

1

u/xlr8__ Dec 16 '15

As another comment says you don't need most of this shit in React. React doesn't need an headless browser in order to run tests for instance, unlike AngularJS 1.

-3

u/fahq2m8 Dec 16 '15

This comment is fucking retarded. Did you bother to stop and think that maybe all that junk shit you mentioned isn't needed in react?

1

u/buttonkop666 Dec 17 '15

There are actually a few people in this subreddit that work on real-life, mission critical applications. Our flagship product is subject to quarterly reviews by independent security auditors. The JS-hipster "throw a million libraries in there and refactor your data layer to the latest brain dead implementation of Flux every month" doesn't cut it.

Edit: disregard, just looked at your comment history. LOL.

10

u/techsin101 Dec 15 '15

i agree angular may never recover now.

3

u/wreckedadvent Yavascript Dec 15 '15

Is it? Last I recall, this is around the date that they were shooting for to start releasing angular 2.0.

4

u/TeamHelloWorld Dec 15 '15

Nice, but

Making the Angular CLI usable end to end throughout the development process.

This is the deciding factor for me.

1

u/newmanoz Dec 15 '15

There are more complete solutions: https://github.com/mgechev/angular2-seed

4

u/9thHokageHimawari Dec 15 '15

I've started wondering.. is it worth using Angular2 for small-scale apps? It feels like I would be better with something else :/

10

u/lingodayz Dec 15 '15

React is nice and simple. And is only concerned with the view. Use whatever you like elsewhere.

2

u/9thHokageHimawari Dec 15 '15

Never liked .jsx, but I guess I gotta check it out.

Flux is something like M/C, but its bound to V right?

6

u/jbarket Dec 16 '15

Once you actively use JSX, I think it becomes a lot less weird. I still wish conditionals in it were first class citizens, but it's never stopped me from getting stuff done.

Comparing React to MVC is always a bit weird. People say it's the V, but components can have any kind of logic in there you want. You can retrieve data when the component loads, bind it to the view, send AJAX events back out when you update data, et cetera.

There's just no strict pattern to it. You're doing all of that in plain old JS, and React is really just responsible for rendering what you do and providing some life cycle hooks.

The Flux pattern solves a lot of problems you end up with when you do this, like sharing information between components, and organizing code in a way that lets you make your components dumber (which makes them easier to reuse).

I highly recommend just playing with vanilla React for a bit. It's super fast to learn, enjoyable to use, and you will quickly figure out why patterns like Flux exist. I had no appreciation for all of the extra files and boilerplate of Redux until I started building something in React, and suddenly it all made sense.

6

u/AshamedOfYou Dec 16 '15

Agreed 100%. JSX is weird for about 5 minutes or so. Another advantage of it is that it demands a proper build system which will also pay dividends down the line.

4

u/Untit1ed Dec 16 '15

I still wish conditionals in it were first class citizens

Check out https://github.com/AlexGilleran/jsx-control-statements

(disclaimer: self-promotion)

1

u/brianvaughn Dec 16 '15

I still wish conditionals in it were first class citizens

IMO a decent enough solution is just to take advantage of short circuit behavior: {someBooleanCondition && <MyComponent/>}

Pardon the awful lack of markup. My phone makes such comments difficult to format.

2

u/_wsgeorge Dec 15 '15

I've started wondering.. is it worth using Angular2 for small-scale apps?

This is exactly what I'm doing: using ng2 for a small scale app. I don't see any problem with that.

3

u/9thHokageHimawari Dec 15 '15

My vanillaJS app is smaller than minified ng2+es6 shim+System.js :/

1

u/Mentis1 Dec 15 '15

They're going to have server-side pre-rendering available, so that should help reduce some of the initial load cost. I think its much more enjoyable developing in ng2 than vanilla, so if by small app you mean hobby project, it's definitely worth it!

1

u/_wsgeorge Dec 15 '15

Oh okay. I see what you mean. According to the post, one of the next few goals is to reduce the payload size, so that might help.

1

u/9thHokageHimawari Dec 15 '15

Should have said extra-small I guess.

1

u/tebriel Dec 16 '15

It's not even worth using angular1 for small-scale apps. :-D

5

u/NotJustClarkKent Dec 16 '15

Angular had its run. I use React for components and Ember for full-fledge SPA's. Angular v2 just took to many twists and turns for me to try to follow it.

8

u/xintox2 Dec 16 '15

Angular2 is dead on arrival. Everyone is moving away from angular to react and aurelia.

5

u/pokemongo Dec 16 '15

Except you're wrong. Tons of companies still use it. There's a place for both.

3

u/xlr8__ Dec 16 '15

Tons of company used to use Zend Framework in the PHP world, then Symfony came by and all these "companies that are slow to move to something else" moved their server stack to Symfony 2. The rise of AngularJS was swift, its demise might be equally fast.

3

u/[deleted] Dec 16 '15

Yeah we still use Angular. We also still use Cobol.

4

u/xintox2 Dec 16 '15

I've been casually interviewing the last 6 months and every single company. Around 20-30 is moving away from angular 1 to react. They are not even considering angular 2. A few are looking into aurelia for the next year.

8

u/x-skeww Dec 16 '15

They are not even considering angular 2.

Given that Angular 2 just went form alpha to beta, that's not really surprising, is it?

Why would anyone use an alpha version of a framework for anything remotely serious?

2

u/xintox2 Dec 16 '15

They aren't even considering it. Aurelia is still beta but they are consider that over Angular and react because the trust was lost when Google abandoned the Angular 1 and made everyone's applications unable to upgrade.

1

u/x-skeww Dec 16 '15

Aurelia is still beta but they are consider that over Angular

Which was alpha.

https://en.wikipedia.org/wiki/Software_release_life_cycle#Stages_of_development

Pre-alpha -> alpha -> beta -> release candidate -> release

5

u/peduxe |o.o| Dec 16 '15

Or just React.

8

u/xintox2 Dec 16 '15

Mostly react but I'm starting to see job descriptions with Aurelia. Someone is paying attention at those companies.

3

u/[deleted] Dec 16 '15

Cross posting from /r/angularjs

This is awesome.

I really like what I have seen so far of Angular 2.

I have a couple of concerns though:

==

The upgrade path seems very messy.


Earlier on in the development of Angular2, there basically wasn't one.

The advice was to componentize your 1.x app, and that would make it easier to upgrade to 2.

This is what I did, and I know other Angular devs who did the same thing.

The thing is, I feel as though this was the right advice!

I now have an Angular 1.4.x app which I feel as though I can rewrite in 2.x, without too much pain, having followed the early advice of rigorous componentization (although time will tell).

I think that creating a new project for your 2.x version and actively developing it, while putting your 1.x app into maintenance-mode, is the correct advice here. Especially if you followed the advice given earlier on about componentization.

Instead what we seem to have is a system where you load Angular 1.x alongside angular 2.x, alongside a third bridging library potentially, and upgrade gradually.

That is at least one more, fairly heavy (even when GZipped) HTTP request when anybody lands on your website. It also makes everything much less simple, and I have the impression that many developers will begin to upgrade their apps, but never really see it though, leaving them in a bit of a limbo, which really bothers me.

2.

The name!


Because it has very little in common with 1.x, I feel as though it should have been given a new name.

3.

3rd party libraries.


This follows on from point 2.

When looking for 3rd party libraries, especially the less well known ones, it is going to be really unclear which libraries are compatible with 1.x, which with 2.x, and which with both!

Both frameworks are incompatible with each other, but yet a search for angular markdown editor, for example, will in the future return a mix of results for Angular 1 and 2. I can see a lot of developers finding this frustrating (especially new ones) and eventually throwing in the towel and giving up.

4.

Third party libraries (again).


Another point about third party libraries is that there are a lot of them, and many of them are really good, and essential to our apps.

I know that the team behind Angular Directives for Bootstrap are working on a version for 2.0 which is awesome, but what about other 3rd party libraries, such as TextAngular, or Angular UI Router, or the many many more?

When a really good 3rd party library is a key part of your app, but the project is a bit stagnant on Github, it makes upgrading to 2.0 that much more difficult.

5:

Routing


What is the deal with routing in the beta? I have been following the development quite closely of Angular 2.0 and I don't have a clue, can somebody bring me up to speed on that?

That is all

Just wanted to share my concerns as a regular Joe AngularJS developer.

In general I think it looks great, very excited to dive into TypeScript, and happy to see that a lot of the more cumbersome aspects of 1.x are gone, but still a few key concerns.

Cheers

3

u/AlGoreBestGore Dec 16 '15 edited Dec 16 '15

All the third-party modules are definitely going to be an issue. IMO they alienated too many people by throwing everything out the window and I'm not sure that people will "come back" and rewrite their modules to Angular 2.

I can see myself sticking around with Angular 1 while they support it/until I have the opportunity for a rewrite and then switching to React.

-2

u/SomeRandomBuddy Dec 16 '15

Anyone remember the times where saying ANY of the things ITT resulted in downvote brigades? 😄

3

u/tebriel Dec 16 '15

Funny, I say the same things about react and get the downvote brigade.

4

u/temp309499 Dec 16 '15

Well of course, that's how the JavaScript world works. If you think about something and point out problems with it you "think you're smarter than the library developers"; if you jump on the newest shiny, build your entire company around it, then go down in flames because of it, you have "real world experience".

2

u/tebriel Dec 16 '15

lol. I tend to avoid the newest shiny for that exact reason.

0

u/[deleted] Dec 16 '15

[deleted]

8

u/franksvalli Dec 16 '15

This is frontend web development in general though. This year's trend is React, but next year it'll be something completely different.

0

u/[deleted] Dec 16 '15

[deleted]

4

u/djbft Dec 16 '15

Isn't Ad Words using angular2 with dart? That's a pretty big property.

1

u/bmrobin Dec 16 '15

yes as well as Google Fiber's site