繁体   English   中英

将Angular2组件转换为ES6语法需要什么?

[英]What do I need to convert my Angular2 component to ES6 syntax?

index.js

这是我的切入点

import * as stylesheet from '../assets/styles/app.scss';

import jQuery from '../node_modules/jquery/dist/jquery';
import $ from '../node_modules/jquery/dist/jquery';

import {bootstrap}    from './boot'
import {AppComponent} from './app.component'

bootstrap(AppComponent);

app.component.js

这有效

(function (app) {
    app.AppComponent = ng.core
        .Component({
            selector: 'my-app',
            template: '<h1>My First Angular 2 App</h1>'
        })
        .Class({
            constructor: function () {
            }
        });
})(window.app || (window.app = {}));

我尝试使用如何在没有装饰器语法的情况下编写angular2的答案 没有成功。

  • 如何摆脱IIFE并使用ES6语法?

未经测试!

import {Component} from 'angular2/core';

@Component({
  selector: 'my-app',
  template: `
    <h1>
        My First Angular 2 App
    </h1>
  `
})
export class AppComponent {
  constructor () {

  }
}

也许你认为你需要app变量有点困惑?

为了清楚你不需要引用app ,你只需要导入AppComponent (就像你已经拥有的那样)

如果您正在使用Babel并使用以下插件: 'angular2-annotations', 'transform-decorators-legacy', 'transform-class-properties', 'transform-flow-strip-types' ,则无需转换语法。

您也可以在一个工作示例中查看它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM