【问题标题】:Angular 5 with es5带有 es5 的 Angular 5
【发布时间】:2017-12-09 17:11:39
【问题描述】:

Angular 4 支持以下语法

var HelloComponent = ng.core
 Component({
    selector: 'hello-cmp',
    template: 'Hello World!',
    viewProviders: [Service]
  .Class({
   constructor: [Service, function (service) { 
   },`
  });

在 Angular 5 中,缺少 Class,目前任何人都可以为 Angular 5 提供 ES5 语法 我无法切换 ES6,所以请避免该建议。 如果切换到 ES6 是唯一的方法,那么我现在将坚持使用 Angular 4

【问题讨论】:

    标签: javascript angular


    【解决方案1】:

    您需要在您的组件 class 上使用静态属性 annotationsparameters,如下所示:

    function Service() {}
    
    function AppComponent(service) {
      console.log(service);
    }
    
    AppComponent.prototype.ngOnInit = function() {
      console.log('test ngOnInit');
    };
    
    AppComponent.annotations = [
      new Component({
        selector: 'my-app',
        template: '<h1>Example of Angular  5.0.5 in ES5</h1>',
        viewProviders: [Service]
      })
    ];
    
    AppComponent.parameters = [ Service ];
    

    Plunker Example

    【讨论】:

    • Angular6 和 JS ES5 有变化吗?
    猜你喜欢
    • 2017-06-24
    • 2016-02-01
    • 2018-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多