角度5与es5 [英] Angular 5 with es5

查看:98
本文介绍了角度5与es5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Angular 4支持以下语法

Angular 4 supports below syntax

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

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

In Angular 5 , Class is missing anyone can provide Angular 5 with ES5 syntax currently i am not able to switch ES6 so please avoid that suggestion. if switching to ES6 is the only way then i will stick to angular 4 as of now

推荐答案

您需要使用静态属性注释参数组件上的 class 函数如下所示:

You need to use static properties annotations and parameters on your component class function something like this:

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示例

Plunker Example

这篇关于角度5与es5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆