0

I begin with AngularJS 2 helped with the hello2ng2 (getting started).

I've created 2 files :

index.html :

<head>
    <title>Angular 2 Hello World!</title>
    <script src="/dist/es6-shim.js"></script>
</head>

<body>

    <my-app></my-app>
    <script>
    // Rewrite the paths to load the files
    System.paths = {
        'angular2/*': '/angular2/*.js', // Angular
        'rtts_assert/*': '/rtts_assert/*.js', // Runtime assertions
        'app': 'app.es6' // The my-app component
    };

    // Kick off the application
    System.import('app');
    </script>
</body>

</html>

And app.es6 :

import {Component,template} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';

// Annotation section
@Component({
  selector: 'my-app'
})
@Template({
  inline: '<h1>Hello {{ name }}</h1>'
})

// Component controller
class MyAppComponent {
  constructor() {
    this.name = 'World!';
  }
}

bootstrap(MyAppComponent);

When I use the http-server (installed with npm), the "Hello World!" is not displayed with Chrome, but it is with Firefox. Any idea why ?

Thank you for your help :)

Pardeep Jain
  • 84,110
  • 37
  • 165
  • 215
JulienBlc
  • 124
  • 2
  • 13
  • Version of Chrome you have support es6? – Bruno Garcia Feb 06 '16 at 18:50
  • whats the error in chrome ? and there is error in your imports check Updated imports list here for angular2 beta http://stackoverflow.com/a/34697758/5043867 – Pardeep Jain Feb 06 '16 at 19:21
  • I have 2 errors in the console : - `es6-shim.js:4941 Uncaught SyntaxError: for-in loop variable declaration may not have an initializer.` And - `(index):13 Uncaught ReferenceError: System is not defined` @Pardeep, thank you ! Indeed, the imports have changed. But for bootstrap, in my folder I don't have a platform folder :/ – JulienBlc Feb 07 '16 at 16:00
  • have you import `system.js` properly in your index.html ? error `(index):13 Uncaught ReferenceError: System is not defined` occured when there is problem in your imports of file. check this answer for proper answer of imports of `system.js`. secondly try to import `CORE_DIRECTIVES` in your directive list of component annotation. – Pardeep Jain Feb 07 '16 at 17:19
  • I've used again npm install, and saw that there was a problem about the zone.js. I've installed it, and now it works ! I don't really understand why, gonna try to understand. – JulienBlc Feb 07 '16 at 18:44
  • your project is running without problem ? well Done !! – Pardeep Jain Feb 08 '16 at 04:29
  • Yeah, that's cool. If anyone have the same issue, be sure when you run your npm to have NO err ! Only warn ;) – JulienBlc Feb 08 '16 at 15:05

0 Answers0