Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does import work in Angular 2?

Tags:

angular

I followed the QuickStart from Angular2. And I made the folder structure different compare to the tutorial. And I encounter an error that cannot find module ....

I understand the cause of the error is import issue.

My folder structure: enter image description here

I have export the hero interface in the hero.ts file. And I want to import this interface in hero-detail.component.ts file.

I had tried:

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

None of these are working.

The system configure in the index.html

enter image description here

My Question is:

How does import work in Angular 2?

like image 769
Shaohao Avatar asked Feb 09 '23 00:02

Shaohao


1 Answers

Then you'd probably need something like

import {Hero} from '../hero';
like image 95
Günter Zöchbauer Avatar answered Feb 11 '23 17:02

Günter Zöchbauer