0

I'm a beginner with typescript and want to know why I can't import an image from my assets folder. I have an image folder and vscode says that the module cannot be found.

This is the error I got:

ERROR in src/app/tool-box/tool-box/ao-bar/ao-bar.service.ts:3:19 - error TS2307: Cannot find module '../../../../assets/objects-ao-bar/fabio.png'.
import Fabio from '../../../../assets/objects-ao-bar/fabio.png';
Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
ℹ 「wdm」: Failed to compile.
pzaenger
  • 11,381
  • 3
  • 45
  • 46
Eduardo Kuhn
  • 1
  • 2
  • 2

1 Answers1

0

There is no need to import an image in typescript. Most likely you are trying to add an image in your angular project refer to this.

Prithvi Singh
  • 50
  • 1
  • 5
  • i want to save an image in a variable but when i import myImg from '../../assets/myimg.png' it doesn't find the image – Eduardo Kuhn Jan 12 '20 at 19:42
  • Are you going to process images bitmap? How are you going to use loaded image object in your TypeScript? – Vitalii Ilchenko Jan 12 '20 at 19:59
  • well, i have an array in which i add objects and each object consists of id, name and img. then i will display the image. I have the image in my assets folder, I want to save the image in a variable so that I can access object.img – Eduardo Kuhn Jan 12 '20 at 21:48
  • In this case each item in your array should hold "id" and "imageUri" (string field, which will store the path to your image). Later you can bind it like `` in your HTML. In Angular there is no sense to load image assets as TypeScript objects. – Vitalii Ilchenko Jan 12 '20 at 22:19