4

I really want to start learning Angular2 but the thing is I don't like the idea of having typescript. I want to do it using pure Javascript. But it seems like there is no proper documentation made for it. Do you have any recommended links where I could start with? 2nd question will be: Is it really worth learning Angular with Javascript since it has no docs for it? Or should I just embrace Typescript?

Estus Flask
  • 206,104
  • 70
  • 425
  • 565
  • 2
    Possible duplicate of [Angular 2 dependency injection in ES5 and ES6](https://stackoverflow.com/questions/38859198/angular-2-dependency-injection-in-es5-and-es6) – Estus Flask Jul 31 '17 at 02:08
  • 3
    Of course, it [has docs for it](https://angular.io/guide/ts-to-js). – Estus Flask Jul 31 '17 at 02:09
  • 5
    Go the typescript way. Think of it as a typed javascript. – BogdanC Jul 31 '17 at 02:49
  • 3
    Typescript is really easy to understand. if you know oops structure then you won't find it hard to understand. Plus it is superscript of JavaScript. – The Hungry Dictator Jul 31 '17 at 04:12
  • 3
    @estus, check on your suggested link. IT HAS NO DOCS FOR IT. –  Nov 09 '17 at 06:17
  • 1
    @meow Because things change, the links in the comments cannot stay valid forever. It's currently in Angular 2 docs. https://v2.angular.io/docs/ts/latest/cookbook/ts-to-js.html – Estus Flask Nov 09 '17 at 09:41

3 Answers3

5

Or should I just embrace typescript?

Yes.

As a practical matter, you are going to find very few, if any, code examples, gists, tutorials, or blog posts that describe Angular without using TypeScript.

The reason is that 95%, or probably more like 99.9%, of Angular users are using TypeScript. That is because it brings a lot of benefits with very few drawbacks. You should re-examine your reasons for not liking the idea of having TypeScript. Yes, there's a learning curve, but it's also an investment in your future, one that will start paying dividends from day one in the form of improved productivity and code quality.

The only really compelling reason for trying to use Angular from JavaScript is if you want to use some subset of Angular's functionality, such as perhaps DI, from a non-Angular application.

2

It is possible to develop an application with ES5, ES6 or ES.next (transpiled with Babel). The difference between them and TypeScript is how DI and modularity are implemented. This example shows how it's done. And this document in Angular 2 documentation explains the differences.

JavaScript is currently considered second-class citizen in Angular development.

Almost all learning resources use TypeScript, which is not a problem if a developer knows how this code translates to JavaScript; the conversion involves the removal of types and refactoring DI annotations. If a developer doesn't use Babel for transpilation, he/she should be aware of modern JS features that are supported by TypeScript but not target browsers.

The problem is that JavaScript isn't supported by official Angular CLI tool and Ahead-of-Time compilation. This seriously limits the usage of Angular JavaScript applications in production.

Estus Flask
  • 206,104
  • 70
  • 425
  • 565
1

I'm adding another answer here with some real technical points.

It is possible to get something running using JavaScript and not TypeScript. But you will have two major problems which mean you shouldn't do it:

  1. You will need to do a lot of configuration. Here is a good article explaining how it can be done, but you'll have to make some changes to get it working with the latest version of babel and webpack, which is not trivial.

  2. You will never be able to get the production bundles down to a sensible size. This is because you won't be using the angular-cli to do your builds, but will instead be using purely webpack. angular-cli appears to do some intelligent building with webpack and the typescript compiler to output much smaller, production bundles. For this reason alone, it's a non starter. The smallest bundle I've managed to get for a hello world app is over 800kB. The equivalent app built with typescript is about 140kB.

I feel that the angular team should update their documentation to point this out.

Ed Spencer
  • 462
  • 1
  • 8
  • 21