-
Notifications
You must be signed in to change notification settings - Fork 12k
Compiling app with --base-href does not prefix image src attribute value with --base-href value #9347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Heya, thanks for the detailed issue and reproduction! This is a known limitation where assets in HTML are not processed. You can read more about it #6666. Workaround for now is to load that image in a CSS file. |
Relative asset URL's present within a component's HTML template will be affected by the base HREF (this is in direct contrast to the |
This is wrong, I think.
Folder assets will be in the root of your deployed location. Therefore the path should be:
At least that worked for me. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Versions
ng --version
@angular/cli: 1.4.3
node: 8.9.1
os: win32 x64
npm --version
5.5.1
Repro steps
<base href="/" />
in the index.htmltransition-indicator
atapp/widgets/
(the resulting directory tree should beapp/widgets/transition-indicator/transition-indicator.component.{ts,html,scss,spec.ts}
.transition-indicator.component.html
and use an<img />
where thesrc
is relative and stored inassets/
. Mine is<img src="../../../assets/images/loading/fading-lines-loader-32x32.gif" alt="Loading..." />
.app/assets/images/loading/fading-lines-loader-32x32.gif
app.module
so it declaresTransitionIndicatorComponent
.home
(the resulting directory tree should beapp/home/home.component.{ts,html,scss,spec.ts}
).<app-transition-indicator></app-transition-indicator>
fromHomeComponent
's view template.app.route
that loadsHomeComponent
.ng build --environment=dev --base-href /angular-app-2/
Let's assume your application is at
C:\angular-app-2
.Configure your local IIS / Nginx / Apache to host a new virtual website at
http://localhost/angular-app-2
.C:\angular-app-2\dist
http://localhost/angular-app-2
in the browser. Notice all assets loaded correctly in the browser developer tools (network tab), except the image that was referenced by thetransition-indicator
component.Here's a ZIP with the project that can reproduce this. https://www.dropbox.com/s/euoyxria5lzfbrk/angular-app-2%28angular%20cli%20bug%29.zip?dl=0
Observed behavior
The Angular CLI compiler is not updating the
transition-indicator
component's<img/>
tagsrc
attribute to request the loading GIF from/angular-app-2/assets/images/loading/fading-lines-loader-32x32.gif
and instead thesrc
value is/assets/images/loading/fading-lines-loader-32x32.gif
.This results in a HTTP request to
http://localhost/assets/images/loading/fading-lines-loader-32x32.gif
instead ofhttp://localhost/angular-app-2/assets/images/loading/fading-lines-loader-32x32.gif
.Desired behavior
I would expect the loading image to be loaded from
/angular-app-2/assets/*
because the Angular CLI build command sets the<base />
elementhref
to/angular-app-2/
.Mention any other details that might be useful (optional)
The purpose of this build style is to host multiple apps under the same sub-domain (one sub domain for each environment like sprint staging, release staging, production staging, etc), but each app using their own unique sub-path. In this case my sub-domain is for all applications that are in the current Agile Sprint iteration (sprint-stage.mydomain.com).
I have two Angular applications:
ng build --environment=dev --base-href /angular-app-2/
so the app will run on the sub-path /angular-app-2/.I'm using a custom environment file for my
stage-sprint
environment so normally the command isng build --environment=stage-sprint --base-href /angular-app-2/
; but for simplicity of this issue I replaced it with--environment=dev
.The text was updated successfully, but these errors were encountered: