How does import work in Angular 2?

I followed QuickStart with Angular2. And I made the folder structure compared to the tutorial. And I encounter an error that can not find the module ... .

I understand that the cause of the error is import .

My folder structure: enter image description here

I exported the interface heroto the hero.ts file. And I want to import this interface into a file hero-detail.component.ts.

I tried:

import {Hero} from '../app/hero';
import {Hero} from './hero';
import {Hero} from './app/hero';

None of them work.

System configuration in index.html

enter image description here

My question is:

How does import work in Angular 2?

+4
source share
3 answers

Then you probably need something like

import {Hero} from '../hero';
+6
source

It must be associated with the SystemJS configuration.

SystemJS, HTML:

<script src="node_modules/systemjs/dist/system.src.js"></script>

SystemJS JS :

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

, shoud !

, , Thierry

+2

To go up:

import {Hero} from './../hero';
0
source

Source: https://habr.com/ru/post/1624480/


All Articles