CodyBugstein
CodyBugstein

Reputation: 23302

How does Angular 2 know where to import things from?

I was looking at Angular 2 Quickstart and I noticed these lines at the top of the angular files

import {bootstrap}    from 'angular2/platform/browser';
import {AppComponent} from './app.component';

My question is, how does the browser know where to find angular2/platform/browser and ./app.component? These are not the correct paths in any meaningful way.

Upvotes: 3

Views: 92

Answers (1)

Thierry Templier
Thierry Templier

Reputation: 202138

When you import the angular2.dev.js, a set of modules is registered explicitly using System.register('module-name', ....

For your application TypeScript file, it's a bit different. When compiling them with the TypeScript compiler, an anonymous module is defined within the corresponding JS file. This means that you need to configure SystemJS to link a module name with the JS file.

With the following configuration, it will deduce that modules that starts with app must be loaded from an URL. For example, import {...} from 'app/main'; will corresponds to http://localhost:3000/app/main.js.

System.config({
  packages: {      
    app: {
      format: 'register',
      defaultExtension: 'js'
    }
  }
});

Upvotes: 2

Related Questions