angular: Angular 2 will not work with RequireJs

I have created a very simple angular app with pure javascript as follows:

<html>
<head>
    <script type="text/javascript" src="require.js"></script>
    <script type="text/javascript" src="angular2.sfx.dev.js"></script>
    <meta charset="UTF-8">
    <title>Angular 2 Test</title>
</head>
<body>
    <my-app>Hello World</my-app>
    <script type="text/javascript">
            (function() {
                var AppComponent = ng
                        .Component({
                            selector: 'my-app',
                            template: '<h1>My First Angular 2 App</h1>'
                        })
                        .Class({
                            constructor: function () { }
                        });

                document.addEventListener('DOMContentLoaded', function() {
                    ng.bootstrap(AppComponent);
                });
            })();
    </script>
</body>
</html>

I got “Uncaught TypeError: Cannot read property ‘_setAsap’ of undefined” error in chrome dev tool. However, if I removed require.js, it works perfectly.

I am wondering how can I use both Angular 2 and RequireJs, because part of my project needs RequireJs to load scripts.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 20 (8 by maintainers)

Most upvoted comments

The SystemJS loader (recommended) will load AMD files and uses the same configuration syntax, fwiw.