Angular 2 TS和Angular 2 Dart有什么区别? [英] What's the difference between Angular 2 TS and Angular 2 Dart?

查看:179
本文介绍了Angular 2 TS和Angular 2 Dart有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Angular 2和Dart有什么区别?

What's the difference between Angular 2 and Dart?

我读到您可以将AngularJS与dart一起使用.那是什么意思?他们不是都是JavaScript的替代品吗?

I read you can use AngularJS together with dart. What does that mean? Aren't they both a JavaScript replacement?

推荐答案

更新(2018/01)

虽然模板语法仍然非常相似,但自从两个版本于2016年5月分离以独立开发以来,诸如配置DI和注册组件以及生命周期回调之类的其他事情在Angular的Dart和TS风格之间就越来越多了

While the template syntax is still quite similar, other things like configuring DI and registering components and also lifecycle callbacks are diverging more and more between the Dart and TS flavors of Angular since the two versions were split in May 2016 to be developed independently.

原始

TypeScript是JavaScript的超集,它只允许以更理智"的方式使用JS.

TypeScript is a superset of JavaScript, it just allows to use JS in a more "sane" way.

Dart凭借其自身的语言语义与JavaScript相距甚远. Dart可以翻译成JS.

Dart is further away from JavaScript with it's own language semantics. Dart can be translated to JS though.

哪种语言最适合您取决于您​​的要求或个人喜好(或您的管理层).

Which of the supported languages is the right one for you depends mostly on your requirements or personal preference (or the ones of your management).

  • 所有3种语言的模板绑定语法几乎相同
[prop]="value"`
[attr.attrName]="value"
prop="{{value}}"`
attr.attrName="{{value}}"
(event)="..."
<div *ngFor="...">

我想到的一个区别是,TS/JS版本获得了<ng-container>,Dart中尚未提供该<ng-container>. @ContentChildren()的行为有些不同.

One difference that comes to mind is that the TS/JS version got the <ng-container> which is not (yet) available in Dart. @ContentChildren() behaves a bit different.

  • 绑定表达式所支持的语言构造已经相差很多,因为它们是所用语言的一部分.
[ngClass]="{cName: value}

如果cName在当前作用域中不是已知的标识符,则

将在Dart中引起错误,而在JS/TS中,cName只是按字面意义使用.

will cause an error in Dart if cName is not a known identifier in the current scope while in JS/TS cName will just be used literally.

[attr.someAttr]="someProp ?? true" // Dart only

  • Angular2 Dart没有NgModule,它主要是为路由器的延迟加载而引入的. Dart有自己的延迟加载故事,不需要NgModule

    • Angular2 Dart doesn't have NgModule which was mainly introduced for lazy loading with the router. Dart has it's own lazy loading story and doesn't need NgModule

      TS/JS支持不同的平台,例如服务器端渲染,WebWorker. Angular2 Dart当前不提供这些功能.
      使Darts自己的HTML抽象dart:html与服务器端代码兼容的工作正在进行中,这可能允许服务器端呈现. WebWorkers最终也可能会得到支持,但其支持方式与TS/JS不同.

      TS/JS supports different platforms like server-side rendering, WebWorker. Angular2 Dart currently doesn't provide these.
      There is ongoing work to make Darts own HTML abstraction dart:html compatible with server-side code, which will probably allow server-side rendering. WebWorkers will probably also supported eventually but in a different way than in TS/JS.

      对于Dart,没有动态平台.在JS/TS中,支持在运行时编译组件. Dart不支持该功能,而且可能永远不会支持.

      For Dart there is no dynamic platform. In JS/TS it is supported to compile components at runtime. That's not supported in Dart and it probably never will be.

      Dart在AoT中似乎可以通过摇晃来提高输出大小和性能(并不完全确定-需要基准)

      Dart seems to do a bit better in AoT with tree-shaking for output size and performance (not entirely sure - needs benchmarks)

      Dart有它自己的构建故事,该部分的工作方式与JS/TS完全不同.

      Dart has it's own build story and this part works entirely different than JS/TS.

      Darts DOM抽象层dart:html为JS/TS需要polyfill的不同浏览器提供了很多抽象.

      Darts DOM abstraction layer dart:html includes a lot of abstraction for different browsers where JS/TS requires polyfills.

      这篇关于Angular 2 TS和Angular 2 Dart有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆