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

后端 未结 7 1612
暗喜
暗喜 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:11

    A simple way to write plain javascript es5 components:

    (function() {
    
        var MyComponent = ng.
            Component({
                selector: 'my-component'
            })
            .View({
                templateUrl: 'my-component.html'
            })
            .Class({
                constructor: function () {
                    this.someArray = [];
                },
                someCustomFunction: function(item) {
                    this.someArray.push(item);
                    ...
                }
            })
    
        document.addEventListener('DOMContentLoaded', function() {
            ng.bootstrap(MyComponent);
        });
    
    })();
    

    Here is a simple todo list demo using Javascript es5.

提交回复
热议问题