繁体   English   中英

角度5与es5

[英]Angular 5 with es5

Angular 4支持以下语法

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

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

您需要在组件 函数上使用静态属性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示例

暂无
暂无

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

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