Angular 2 @Component语法是ES6的一部分吗?

scr*_*key 7 typescript ecmascript-6 angular

有谁能告诉我.'@'导入的Component函数前面的符号.这是ES6语法吗?我没有看到它用于我看过的任何其他非角度ES6项目.

import {Component} from ...
@Component({})
Run Code Online (Sandbox Code Playgroud)

这是一个例子

Hug*_*ois 18

@语法是ES7一个新的草案这是目前在阶段1(提案阶段)的一部分.他们被称为装饰者.

装饰器使得可以在设计时注释和修改类和属性.

有关更多信息,请参阅:https://github.com/wycats/javascript-decorators


注意:您可以使用装饰器,通过启用(在webpack中)或通过将配置设置为使用Babeloptional[]=es7.decoratorsstage:1


jed*_*ung 5

简答:不.

@语法定义的注释-这是由角的介绍AtScript,后来合并为打字稿.从我所看到的,它们类似于.NET语言中的注释.

注释不是标准ES6的一部分; 它们只是TypeScript提供的装饰.值得注意的是,Angular 2支持使用TypeScript注释,Aurelia也是如此.

我目前无法提供链接,但有一些资源可以非常详细地描述ES6的功能和语言组件.


Sim*_*ara 5

仅针对记录,只需将TypeScript注释转换为以下内容,即可在ES6中实现相同的行为:

import {Component, ...} from 'angular2/core';
export class myAppOrDirective {
    static get annotations() {
        return [
            new Component({
                selector: 'my-app-or-directive'
            }),
            new View({
                template: `<div>Hello!</div>`
            })
        ];
    }
}
Run Code Online (Sandbox Code Playgroud)