Background image not found after deploying angular 4 app into tomcat -
i working on angular app , have generated project structure angular-cli. using below css in on of component :
.profilepic{ height:67px; width: 67px; display: block; background: url('/assets/images/header-profile-pic.png') no-repeat center center }
when ng serve
dev purpose ; app runs fine on localhost:4200 , can able load above image.
when ng build --prod
, generates dist
folder, copy dist folder deployment server(tomcat in case) , when try open application, background image doesn't load.
on console shows 404 error.
i have set base tag in html <base href="./">
. in dist folder, assets folder @ root level. if try update css path background: url('./assets/images/header-profile-pic.png') no-repeat center center
; ng-build gives me error,
module not found: error: can't resolve './assets/images/header-profile-pic.png' in 'd:\node\angular 2\router\src\app\login-component'
i have tried this answer's second bullet point , work. want put images in assets folder only.
is there way background image available in both dev prod env.?
update:
as <image
> tag accepts source path, try workaround:
set style online in html:
...[ngstyle]="{'background-image': 'url(/assets/images/header-profile-pic.png)'}" ..
and leave in css:
background: no-repeat center center;
old answer:
you don't have change stylesheet development , production. correct following:
background: url(/assets/images/header-profile-pic.png) no-repeat center center
Comments
Post a Comment