微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – 带有es5的Angular 5

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

解决方法:

您需要在组件类函数上使用静态属性注释和参数,如下所示:

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐