2

I've been following the Angular2 quicstart using javascript in the purpose of learning the Angular2 framework.. I've been doing exactly like the guidelines told me but I'm having an errors

Uncaught TypeError: undefined is not a function angular2-all.umd.js:3528
Uncaught RangeError: Maximum call stack size exceeded angular2-polyfills.js:143

I'm not sure if I missed something, this is the file structure of my app

  • app/
    • app.component.js
    • boot.js
  • node_modules/
  • index.html
  • package.json

and this is the code base

app.component.js

(function (app) {

    app.AppComponent = ng.core
        .Component({
            selector: 'my-app',
            template: '<h1>My First Angular 2 App</h1>'
        })
        .Class({
            constructor: function () {
            }
        });

})(window.app || (window.app == {}));

boot.js

(function(app) {

    document.addEventListener('DOMContentLoaded', function() {
        ng.platform.browser.bootstrap(app.AppComponent);
    });

})(window.app || (window.app = {}));

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Angular 2</title>

    <script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
    <script src="node_modules/rxjs/bundles/Rx.umd.js"></script>
    <script src="node_modules/angular2/bundles/angular2-all.umd.js"></script>

    <script src="app/app.component.js"></script>
    <script src="app/boot.js"></script>

</head>
<body>
    <my-app>Loading..</my-app>
</body>
</html>

I think I followed the quickstart perfectly, but I'm not sure on where did I missed since I'm new to Angular2

1 Answer 1

1

You have a little almost unnoticeable typo in your code that makes a huge difference. This is your IIFE in app.component.js file:

(function (app) {
    // ...
})(window.app || (window.app == {}));
// comparison operator ------^

Note, that you use comparison operator, while you want assignment:

(function (app) {
    // ...
})(window.app || (window.app = {}));
Sign up to request clarification or add additional context in comments.

8 Comments

yes I did a typo, thanks for noticing ! unfortunately that didn't solve the problem though... I still got the error message
Really? Because I actually tested your code - that's how I realised about this typo. It did fix the problem though.
could you share me the tested codes ? or is it possible that browser version caused this issue ?
tried it and it returns Uncaught TypeError: undefined is not a function collection.ts:65 so I guess my chrome has an issue about it ? I run it on ubuntu though
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.