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

后端 未结 7 1611
暗喜
暗喜 2020-12-16 15:46

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 comp

7条回答
  •  余生分开走
    2020-12-16 16:12

    Yes.

    Here are 2 simple components, written in different ways that Angular 2 supports when writing in JavaScript (EcmaScript 5):

    (function() {
    
      var HelloWorldComponent = function() {};
    
      HelloWorldComponent.annotations = [
        new ng.core.Component({
          selector: 'hello-world',
          template: '

    Hello Angular2!

    ' }) ]; var HelloFlentApi = ng.core.Component({ selector: 'hello-fluent', template: '

    Hello {{name}}!

    ' + '', }).Class({ constructor: function() { this.name = "Fluent API"; } }); var AppComponent = ng.core.Component({ selector: 'company-app', template: '' + '', directives: [HelloWorldComponent, HelloFlentApi] }).Class({ constructor: function() {} }); document.addEventListener("DOMContentLoaded", function() { ng.platform.browser.bootstrap(AppComponent); }); }());
    
    
    
    
    
      Loading ...
    

    I wrote a detailed explanation of the code here:

    Writing An Angular2 Component in Today’s JavaScript (ES5) – Beta 0 Edition

    As the link says, this applies to Angular 2 Beta 0, which was released a few hours ago at the time of writing this answer.

提交回复
热议问题