angular - 在 angular html 之间从 assets 文件夹中添加 html
问题描述
我想从我的 Angular 的 html 文件之间的资产文件夹中加载 html。例如:假设这是我的产品组件的 product.html,detailPara.html 和 BlockPara.html 在 assets 文件夹中,我必须在 product.html 之间添加:
<div class="productPage">
....
<div innerHTML="../assets/product/detailPara.html"></div>
....
<div innerHTML="../assets/product/BlockPara.html"></div>
</div>
有人可以帮帮我吗。
解决方案
你可以像这样使用它。
let path = 'assets/' + {fileName} + '.html';
this._httpClient.get(path, {responseType: "text"}).subscribe(
data => {
//now you have the file content in 'data'
this.content = this.sanitizer.bypassSecurityTrustHtml(data);
});
只需在构造函数中注入 DOMSanitizer 就可以了!
然后在您的 HTML 文件中。
<div class="productPage">
....
<div [innerHTML]="content"></div>
....
推荐阅读
- php - 在 php 数组中移动值
- google-sheets - 忽略空单元格的 ImportRange 函数
- reactjs - 使用 setInterval 动态改变图像
- python - == 或 != 在链式比较中是否有用?
- azure-cosmosdb - Azure Cosmos DB Mongo API 存储过程
- android - FirebaseUI 导入:库 com.google.android.gms:play-services-basement 正在被其他各种库请求
- java - 错误:Java:无效的目标版本:11 - IntelliJ IDEA
- python - 如何使用 Selenium 和 BeautifulSoup 从标签中获取文本
- python - 在 django admin 上注册 4 个参数 - TypeError: register() 最多接受 3 个参数(给定 4 个)
- json - 如何使用法拉第的 post 方法将 JSON 作为表单数据发送