Édouard Lopez
Édouard Lopez

Reputation: 43419

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

index.js

Here is my entry point

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

This works

(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 = {}));

Question

I tried to use answer from How do I write angular2 without decorator syntax? without success.

Upvotes: 3

Views: 418

Answers (2)

SoniCoder
SoniCoder

Reputation: 4174

If you are using Babel and use the following plugins: 'angular2-annotations', 'transform-decorators-legacy', 'transform-class-properties', 'transform-flow-strip-types' there is no need to convert the syntax.

You can check it also in a working example.

Upvotes: 1

Ashley Coolman
Ashley Coolman

Reputation: 11585

Untested!

import {Component} from 'angular2/core';

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

  }
}

Perhaps you got a little confused by thinking you needed the app variable?

Just to be clear you don't need to reference app, you just need to import AppComponent (as you already have)

Upvotes: 2

Related Questions