Using Angular 2 without TypeScript Transpiler

后端 未结 2 566
醉酒成梦
醉酒成梦 2020-12-29 08:37

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 tran

相关标签:
2条回答
  • 2020-12-29 09:25

    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> 
    
    0 讨论(0)
  • 2020-12-29 09:31

    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>
    
    0 讨论(0)
提交回复
热议问题