angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

linking an image from template html requires path from app root

Open entzik opened this issue 10 years ago • 8 comments

OS?

OSX El Capitan

Versions.

angular-cli: 1.0.0-beta.21 node: 6.2.2 os: darwin x64

Repro steps.

Was this an app that wasn't created using the CLI? What change did you do on your code? etc.

  • create a component under app, say AppHeaderComponent.

  • in the component directory - app-header - create an 'images' directory.

  • put an image in that directory, say 'company-logo.png'.

  • in the template link the image as '<img src="images/company-logo.png">'. now serve the application

  • serve the app using ng-serve

=> this used to be possible when building with 1.0.0-beta16, the image would show up as expected. when building with 1.0.0.beta21 the image is not found. for it to work, I need to specify the full path from root: "<img src="app/header-panel/images/company-logo.png">. This is annoying because if I decide to refactor the project by renaming the components or moving it deeper in the hierarchy I need to also refactor all the templates. Being able to specify a relative path relative to the template is a big advantage. Also I need to publish this "app-header" as a reusable component, the image belongs next to the template.

The log given by the failure.

no specific log

Thanks! We'll be in touch soon.

entzik avatar Nov 26 '16 20:11 entzik

You are supposed to put images in the assets folder that is inside src folder then you can specify path as assets/../image.png

Nikki1993 avatar Nov 27 '16 07:11 Nikki1993

that would be OK if you're thinking "website". I am thinking "reusable component". that image exclusively belongs to the component and I would like it to stay next to the template that uses it.

entzik avatar Nov 27 '16 08:11 entzik

Ignore my comment, I read the end of your issue :) seems legit :D, yea would be nice to have it in this instance.

Nikki1993 avatar Nov 27 '16 08:11 Nikki1993

We had this in once, by using HTML-loader, but it broke a lot of projects (see https://github.com/angular/angular-cli/issues/2396).

I agree that the scenario you're proposing is super relevant.

filipesilva avatar Dec 29 '16 19:12 filipesilva

Closing in favor of https://github.com/angular/angular-cli/issues/3415, there's some more discussion in that one.

filipesilva avatar May 22 '17 14:05 filipesilva

@entzik . I am looking for a way to do the exact same thing. Embbed an image into component that will be reused. Did you overcome this ? If yes How ?

regards

dlarr avatar Feb 02 '18 13:02 dlarr

Best way I can come up with is to include the image inline, either in the html or the css, Here is a walk through

http://www.websiteoptimization.com/speed/tweak/inline-images/

ryager01 avatar Nov 08 '18 18:11 ryager01

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.