Angular 2 +打字稿或Angular 2 + Javascript,建议使用 [英] Angular 2 + typescript or Angular 2 + Javascript which one is advisable

查看:46
本文介绍了Angular 2 +打字稿或Angular 2 + Javascript,建议使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Angular中有更好的知识,并且在Angular中工作了将近3年.我刚开始学习Angular 2,有点困惑.我应该学习 Angular 2 + Typescript ,或者我可以使用 Angular + JavaScript ES6 .互联网上所有可用的文档都是Angular + typescript.哪个对未来更好?

I have better knowledge in Angular and I have been working on almost 3 years in Angular. I just started learning Angular 2 and bit confused. I should learn Angular 2 + Typescript or I can go with Angular + JavaScript ES6. All the documentation available on internet is Angular + typescript . Which one is better for future?

推荐答案

在Angular2应用程序的上下文中,ES6和TypeScript之间的主要区别如下:

The main differences between ES6 and TypeScript in the context of Angular2 applications are the following:

  • 您不能将类型用于类属性,变量和方法参数.

  • You can't use types for class properties, variables and method parameters.

方法参数的修饰符.例如,对于依赖项注入,您需要为"parameters"属性指定一个静态设置器:

Decorators for method parameters aren't supported. For example for dependency injection, you need to specify a static setter for the "parameters" property:

constructor(http) {
  this.http = http;
}

static get properties() {
  return [[ Http ]];
}

使用TypeScript,您将拥有以下内容:

With TypeScript, you will have this:

constructor(private http:Http) {
}

因此两者都可以在Angular2中使用.该框架在文档中推广了更多TypeScript,但Ionic2(使用Angular2)默认在使用"ionic start"创建的应用程序中使用ES6.因此,您可以自由使用其中一个.

So both are usable in Angular2. The framework promotes more TypeScript in docs but Ionic2 (that uses Angular2) uses by default ES6 in the application created using "ionic start". So you're free to use one or the other.

TypeScript的主要优点是其强类型"功能,该功能使您可以确保提供/返回正确的结构,并且不使用对象上不存在的东西.

The main advantage of TypeScript is its "strong typing" feature that allows you to ensure that the right structures are provided / returned and you don't use something that isn't present on objects.

另一个很酷的事情是开发TypeScript应用程序时,IDE支持自动补全.

Another cool thing is the support of IDEs for autocompletion when developping TypeScript applications.

这篇关于Angular 2 +打字稿或Angular 2 + Javascript,建议使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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