简体   繁体   English

在angular2上找不到图像

[英]Cannot find image on angular2

I am building a new application on angular 2 and it was working perfectly when I used the command (ng serve) from angular-cli. 我在angular 2上构建了一个新应用程序,当我使用angular-cli中的命令(ngserve)时,它运行良好。 However, when I tried to put the application on a tomcat server with the command (ng build or ng build --prod) it did not recognize some of my images. 但是,当我尝试使用命令(ng build或ng build --prod)将应用程序放置在tomcat服务器上时,它无法识别某些图像。 It was not all of them, but only 2, the ones that I was setting as background of a specific component. 不是所有这些,而是​​只有2个,我将它们设置为特定组件的背景。 The codeline is the following: 代码行如下:

<body [ngStyle]="{'background-image': 'url(' + '../../img/image1.jpg' + ') no-repeat fixed center' }">


<div class="panel col-lg-12" [ngStyle]="{'background-image': 'url(' + '../../img/image2.jpg' + ') repeat-x center'}">

I tried to set it on the css file without ngStyle and it did not work either. 我试图在没有ngStyle的css文件上设置它,但是它也不起作用。 It works fine on ng serve, but it does not work when I try ng build. 它可以在ng服务上正常工作,但是在尝试ng构建时不起作用。

Also, I am having another problem with ng build. 另外,我在使用ng build时遇到了另一个问题。 Whenever I try to F5 a page it does not recognize the path. 每当我尝试F5页面时,它都无法识别路径。 It works fine if I click on the links and it does redirect to other pages, but when I try to type the address on the url bar it does not work (except for the home address). 如果我单击链接,它可以正常工作,并且确实可以重定向到其他页面,但是当我尝试在网址栏上键入地址时,它不起作用(家庭地址除外)。

I think, Images are not there inside dist folder which generated by ng build . 我认为, ng build生成的dist文件夹中没有图像。 Please check this dist folder. 请检查此dist文件夹。 I think, this is still bug there. 我认为,这仍然是错误 If it is true, then try to copy and paste that public folder in dist directory. 如果这是真的,然后尝试在dist目录复制并粘贴公用文件夹

Hope this will help you. 希望这会帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM