Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use ES5 JavaScript with Angular 2 instead of TypeScript?

Is it needed to learn TypeScript for Angular 2?

Can Angular 2 be used with plain JavaScript ?

Edit: I've seen that the languages used as ES6, ES7, Dart compile to JavaScript to be executed, but I haven't seen any reference to use ES5 JavaScript directly.

like image 680
jordiburgos Avatar asked Jun 07 '15 01:06

jordiburgos


2 Answers

Angular 5 dropped support for plain ES5.

See the following commit and comment on GitHub: https://github.com/angular/angular/commit/cac130eff9b9cb608f2308ae40c42c9cd1850c4d

like image 194
jbandi Avatar answered Sep 17 '22 21:09

jbandi


Yes, you can.

Go read this guide. Pressing the ES5 tab on the code examples will show you regular ES5 JavaScript, as apposed to TypeScript.

The API preview is, for obvious reasons, incomplete though. So you may not find the ES5 methods listed there yet, and some of it may change before release.

Current example of Angular 2.0 main component in ES5.

function AppComponent() {}

AppComponent.annotations = [
  new angular.ComponentAnnotation({
    selector: 'my-app'
  }),
  new angular.ViewAnnotation({
    template: '<h1>My first Angular 2 App</h1>'
  })
];

document.addEventListener('DOMContentLoaded', function() {
  angular.bootstrap(AppComponent);
});
like image 36
Oka Avatar answered Sep 17 '22 21:09

Oka