angular - 无法在角度应用程序中查看库中的图像
问题描述
我已经创建了带有图像标签的组件的角度库,该标签使用库中资产文件夹中的图像,如下所示
<img src="assets/sample.jpg"/>
我正在尝试在角度应用程序中使用该库。我可以将资产文件夹与库捆绑在一起,并修改我的 angular.json 文件以具有资产选项,如下所示
{ “glob”:“**/*”,“输入”:“node_modules/@uitest/ui-test/assets”,“输出”:“/projects/ui-test-app/src/assets”}
在执行上述步骤时,我看到资产文件夹被复制到与构建它的角度应用程序相关的 dist 文件夹中
但是,如果我使用 ng serve 命令在 localhost 中运行应用程序,则图像不会加载,因为找不到资产文件夹
测试应用程序的 Git 中心链接以重现问题https://github.com/spiderprn/ui-test.git
解决方案
如果您在服务之前将该文件夹复制到资产中,npm run myServe
.
父项目的package.json:
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"build_lib": "ng build ui-test-app",
"copy_files": "copy .\\projects\\ui-test-app\\src\\assets .\\dist\\assets",
"myServe": "npm run build_lib && npm run copy_files && npm run start"
},
推荐阅读
- c - 如何限制用户输入任何 4 位组合,包括以 0 开头的组合并排除 C 中的所有其他字符?
- ruby-on-rails - 通过链接验证匿名用户访问
- python - 从 df 中按类别抽取随机子样本
- javascript - 打包时Webpack忽略数组变量
- javascript - 如何(真正)防止移动设备上的捏缩放
- google-bigquery - 为什么 BigQuery 会扫描整个表,尽管它是按小时分区的?
- xcode - AddressSanitizer 在 MacOS Mojave 上使用 Chromium Embedded Framework 引发崩溃
- database - 从 json 中提取唯一值的 SQLite 查询
- python-3.x - 如何在 python 3 中使用列表理解同时接受来自用户的不同数据类型
- ruby - 我可以在 Ruby 方法中访问隐式 Proc 中定义的方法吗?