Angular 5 with es5

Angular 4 supports the syntax below

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

In Angular 5, there is no class, anyone can provide Angular 5 with ES5 syntax. Currently I cannot switch ES6, so please avoid this suggestion. if switching to ES6 is the only way, then I will stick with Angular 4 for now

+4
source share
1 answer

You need to use static properties annotationsand parametersin your 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 ];

Plunger example

+5
source

Source: https://habr.com/ru/post/1690486/


All Articles