簡體   English   中英

使用沒有TypeScript Transpiler的Angular 2

[英]Using Angular 2 without TypeScript Transpiler

我想學習Angular 2並將我的應用程序切換到使用它,但是,我在使用TypeScript時遇到了問題。

在我目前的環境中,我不能使用transpiler / compiler。 我目前只需要運行node.js可執行文件(node.exe),但不是完整的node.js應用程序,也不是npm。 Angular 2是用TypeScript編寫的,因此需要在發送到瀏覽器之前將其編譯為JavaScript。

有沒有辦法獲得Angular 2的預編譯版本,所以我可以用JavaScript編寫並在沒有編譯器的情況下運行?

如果沒有,有沒有辦法手動安裝和使用TypeScript編譯器只有node.exe可執行文件?

要清楚,這不是因為我不想使用TypeScript,而是因為在我目前的情況下我無法安裝它。

Angular2在TypeScript,JavaScript和Dart中可用。 無需使用TypeScript。

看到
- 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

另請參閱是否可以將ES5 JavaScript與Angular 2而不是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>

如果要使用TypeScript編寫應用程序,則需要一個轉換器:

  • 靜態的。 例如,在后台運行tsc -w命令
  • 在飛行中。 使用typescript.js文件直接在瀏覽器中

也就是說,只能用ES5編寫Angular2應用程序。 這是一個示例:

編輯

當您從Angular2(文件夾node_modules/angular2/bundles )中包含這些JavaScript文件時,沒有任何關於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>

這些文件被轉換為JavaScript。 所以沒有必要使用TypeScript。 有了它們,您只能使用ES6實現您的應用程序。

要僅使用ES5,您需要包含以下內容:

<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> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM