Relative path for static files like images / css / js etc.

I have a folder structure /src/app/some-module/some-componentand src/public/images/user.png. Now that I want to show the image in my some component, I have to specify a path like ../../../public/images/user.pngthat seems too naive and wasteful when the number of images increases.

Do we have a routing mechanism or relative path in angular2 to serve static files. I am using angular2 with a web package.

+4
source share
2 answers

It depends on how your looks base href.

For example, if you have

<base href="/src/">

, , .

<img src="public/images/user.png" />

, !

+5

WebPack, . <img src="..."> , .

, WebPack

<img src="img/rhamt-square-248.png" width="172">

img/ .

WebPack :

<img src="../../../img/rhamt-square-248.png" width="172">

, :

. /src/app/misc/about.component.html
: : './img/rhamt-square-248.png' '/home/ondra/work/Migration/windup-web/ui/src/main/webapp/src/app/Misc '
 @./src/app/misc/about.component.html 1: 402-439
 @./src/app/misc/about.component.ts
 @./src/app/app.module.ts
 @./src/main.ts

+1

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


All Articles