1

I'm starting to take a look at angular2, but with this simple code

<html>
    <head>
            <script src="https://code.angularjs.org/2.0.0-alpha.19/angular2.sfx.dev.js"></script>
            <script>
            function AppComponent() {}

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

            document.addEventListener('DOMContentLoaded', function() {
              angular.bootstrap(AppComponent);
            });
            </script>
    </head>
    <body>
        <my-app></my-app>
    </body>
</html>

I've got the below errors:

SyntaxError: in strict mode code, functions may be declared only at top level or immediately within another function function onGlobalPostMessage(event) {

ReferenceError: angular is not defined new angular.Component({

1 Answer 1

2

I'm assuming you're running this in FireFox? Chrome doesn't seem to have an issue with it.

The problem is that the compiled Angular has an error in it. If you want to continue working in FireFox, download the angular2.sfx.dev.js and modify line 5610 from this:

function onGlobalPostMessage(event) {

To this:

var onGlobalPostMessage = function(event) {

That should get you working again.

I recommend using alpha.21 which is out now, btw, or you can use alpha.20 which is compiled here.

Sign up to request clarification or add additional context in comments.

Comments

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.