Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EmberJS, How to import files using root path?

I have this a model in this path:

/my-project/app/models/my-model.js

And I want to import it from a route in this path:

/my-project/app/routes/battles/battle/combats/new.js

The import sentence looks like this:

import MyModel from '../../../../models/my-model';

The path is insane, I have to use the try and error system to figure out it. Also if I want to import the same model in another component I can't just copy&paste because this path is only valid from an specific path. For the same reason if I change the path of the component importing my model I have to update the import path.

I would like to have path relative to the root of the project, something like:

import MyModel from '/models/my-model';

Is this possible?

like image 834
fguillen Avatar asked Dec 21 '15 12:12

fguillen


1 Answers

Ember CLI registers everything in app/ under the project name, so the import should look like this:

import MyModel from 'my-project/models/my-model';
like image 90
locks Avatar answered Oct 14 '22 13:10

locks