简体   繁体   English

图像未加载到 Angular 应用程序上

[英]Images not loading on Angular Application

I've built and deployed an Angular App using the build command on the cli with the deploy-url option as below:我已经使用 cli 上的 build 命令和 deploy-url 选项构建和部署了一个 Angular 应用程序,如下所示:

ng b -deploy-url /portal/

And my scripts work which is great but everything in the assets folder is showing the console as 404 not found.我的脚本工作很好,但资产文件夹中的所有内容都将控制台显示为 404 not found。 I assumed that the deploy url option would have fixed this as well as the scripts?我认为部署 url 选项会解决这个问题以及脚本? When I inspect the element in the console the url doesn't seem to have the '/portal/' in front of it.当我检查控制台中的元素时,url 前面似乎没有“/portal/”。

<img _ngcontent-c0="" alt="User Avatar" id="user-avatar" src="../assets/users/profile/WebDevelopWolf.png">

So I assume it's looking for the assets folder in the wrong place?所以我认为它在错误的地方寻找资产文件夹? In which case I'm not sure what it will need to find the folder that also won't break my local test where it's just served up using a straight ng serve command.在这种情况下,我不确定它需要什么来找到也不会破坏我的本地测试的文件夹,它只是使用直接的ng serve命令提供的。

Just in case it's relevant, I've deployed this to a Windows 2016 server as an app.以防万一,我已将其作为应用程序部署到 Windows 2016 服务器。

You have to give relative path你必须给出相对路径

src="assets/users/profile/WebDevelopWolf.png"

Angular always points to assets folder provided in angular.json. Angular 始终指向 angular.json 中提供的资产文件夹。

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

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