Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Angular 2 without TypeScript Transpiler

I want to learn Angular 2 and switch my app to using it, however, I'm having a problem with using TypeScript.

In my current environment I can't use a use the transpiler / compiler. I'm currently having to run off of just the node.js executable (node.exe) but not the full node.js application, nor npm. Angular 2 is written in TypeScript, so it needs to be compiled to JavaScript before being sent to the browser.

Is there a way to get a pre-compiled version of Angular 2 so I can write in JavaScript and run without a compiler?

If not, is there any way to manually install and use the TypeScript compiler with just the node.exe executable?

To be clear, this isn't because I don't want to use TypeScript, but rather because in my current situation I can't install it.

like image 424
Binvention Avatar asked Feb 05 '16 17:02

Binvention


People also ask

Is TypeScript required for Angular 2?

Typescript is optional, but strongly recommended.

Can I use Angular without TypeScript?

Angular2 is available in TypeScript, JavaScript and Dart. No need to use TypeScript. See also Is it possible to use ES5 JavaScript with Angular 2 instead of TypeScript? No, it is written in TypeScript.

Can I run Angular without node JS?

Yes. Node. js required for Angular 2 or Angular apps.

Is Angular 2 JavaScript or TypeScript?

Angular is an open-source, JavaScript framework written in TypeScript. Google maintains it and provides a standard structure for developers to work within it. Angular makes use of HTML syntax to define the components of your program clearly.


2 Answers

Angular2 is available in TypeScript, JavaScript and Dart. No need to use TypeScript.

See
- https://angular.io/docs/js/latest/index.html
- http://blog.thoughtram.io/angular/2015/05/09/writing-angular-2-code-in-es5.html
- http://blog.thoughtram.io/angular/2015/07/06/even-better-es5-code-for-angular-2.html

See also Is it possible to use ES5 JavaScript with Angular 2 instead of TypeScript?

<script src="https://code.angularjs.org/2.0.0-beta.3/Rx.umd.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.3/angular2-polyfills.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.3/angular2-all.umd.dev.js"></script>
like image 145
Günter Zöchbauer Avatar answered Oct 04 '22 13:10

Günter Zöchbauer


If you want to use TypeScript to write your application, you need a transpiler:

  • static. For example with a tsc -w command running in background
  • on the fly. Directly within the browser using the typescript.js file

That said it's possible to write Angular2 applications with ES5 only. Here is a sample:

  • http://blog.thoughtram.io/angular/2015/07/06/even-better-es5-code-for-angular-2.html

Edit

When you include these JavaScript files fro Angular2 (folder node_modules/angular2/bundles), there is nothing about TypeScript:

<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="node_modules/angular2/bundles/router.dev.js"></script>
<script src="node_modules/angular2/bundles/http.dev.js"></script>

These files were transpiled into JavaScript. So there is no need to have TypeScript. With them, you can implement your application with ES6 only.

To use ES5 only, you need to include these ones:

<script src="node_modules/angular2/bundles/Rx.umd.js"></script>
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/angular2/bundles/angular2-all.umd.dev.js"></script> 
like image 29
Thierry Templier Avatar answered Oct 04 '22 13:10

Thierry Templier