Navigation problem (through folders) for import


#1

Sorry if I’m a noob, but I have this structure in my project:

src ==> pages ==> HeroesList;
src==> model ==> Hero;

How can I import my hero in the heroesList?

I tried like this:

import { Hero } from './model/hero/hero';
OR
import { Hero } from '../model/hero/hero';
OR
import { Hero } from '../hero/hero';
OR
import { Hero } from '../hero';
OR
import { Hero } from '../model/hero';

#2

src is the root, so I guess if you’ve got

 src/pages/HeroesList.ts
 src/model/Hero.ts

your would have to add following to import Hero.ts in HeroesList.ts

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

if Hero look for example like

export class Hero {
}

Doesn’t that work?


#3

It says that the module …/model/hero wasn’t find…


#4

Would you like to try to put your model under providers?

  src/pages/HeroesList.ts
  src/providers/model/Hero.ts

  import { Hero } from '../providers/model/hero';

#5

Thanks for answer, I tried now but it doesn’t work… I thought it’s only a false alarm and maybe the app run without problems…


#6

Weird I mean that’s exactly my structure

You’ve got the error when you run ionic serve right? you restarted the process after the change?

Do you really have your page right under src/pages/ not under a subfolder like src/pages/heroes or something?


#7

The structure is:

src
  -pages
    -heroeslist
  -model
    -hero

I solved with auto-import! He write this:

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

#8

cool well done congrats