1

I am trying give img src path from outside of angular project .please resolve my problem as soon as possible. My folder structure were look like

       ProjectName
             \backend
                \assets
                  \images\test.png
             angularprojectroot
                  \app
                     \src
                        \component files
suresh
  • 41
  • 4

1 Answers1

1

In file paths you can go up a step with ..

<img src="../../../../backend/assets/images/test.png" />

Definitely for development only. In production serve the test.png from your server.

In your specific case using angular.json add this to your assets:

// assets is an array. Keep the other items in the array but add the one displayed below
"assets": ["../../../backend/assets/images/test.png"]

Then I believe you can just refer to the image as test.png:

<img src="test.png" />
Sydney Y
  • 2,912
  • 3
  • 9
  • 15
  • Fiddle with the number of `../` repeats. VS code will probably help you with that if you're using it. – Sydney Y Feb 09 '20 at 08:20
  • In the browser when you are in development what is the URL? Is it localhost? – Sydney Y Feb 09 '20 at 08:30
  • localhost:4200/ – suresh Feb 09 '20 at 08:31
  • Your project is being served from a server inside the angular project folder, so you can't access the file outside the project. Try going into your file directory in the folder angular made called (build | dist | public) and opening the file index.html in your browser instead. Then you can use `..`. – Sydney Y Feb 09 '20 at 08:34
  • build Time it working fine .i am using in angular.json like this "assets":[ "glob";"**/*", "input":"Outisde project folder", – suresh Feb 09 '20 at 08:53