How do I write angular2 without decorator syntax?

前端 未结 2 1248
慢半拍i
慢半拍i 2021-01-23 11:57

I\'m roughly following JavaScript/TypeScript quickstart for Angular2 to write my app in ES6 but can\'t get the decoractor to works

entry.j

2条回答
  •  渐次进展
    2021-01-23 12:05

    You can use ES5 syntax:

    import * as ng from 'angular2/core';
    
    const SomeComponent = ng
    .Component({ /* ... */})
    .View({ /* ... */ })
    .Class({
        constructor() {}
    });
    
    const SomeDirective = ng
    .Directive({ /* ... */ })
    .Class({
        constructor() {}
    });
    

    So for your case it will be (see this plunk):

    export const AppComponent = Component({
      selector: 'my-app',
      template: '

    Hello {{ name }}

    ' }) .Class({ constructor() { this.name = 'Max'; console.log(this.name); } });

    PS But if I were you, I would try to resolve the problem and continue to use ES7 decorators. Maybe you've forgotten to do npm install?

提交回复
热议问题