【发布时间】:2020-03-14 03:36:50
【问题描述】:
我有以下结构,其中有 json 格式的图像数据,其中包含指向 assets 文件夹的链接。放置所有图像的位置。我正在考虑使用这种使用图像的方式进行测试,因为将来我们将在网络的某个地方拥有图像,并将根据类似的 JSON 从那里获取:
- app
- core
- data
- img.json
- layout
- test.component.ts
- assets
- images
img.json:
{
"items" : [
{
"img": "/assets/images/test1.png",
"alt" : "Image 1"
},
{
"img": "/assets/images/test2.png",
"alt" : "Image 2"
},
{
"img": "/assets/images/test3.png",
"alt" : "Image 3"
}
]
}
test.component.ts:
import images from '../../data/img.json';
export class SlideshowComponent implements OnInit {
showNavigationArrows = false;
showNavigationIndicators = false;
items = [0, 1, 2].map((n) => images);
constructor(config: NgbCarouselConfig) {
// customize default values of carousels used by this component tree
config.showNavigationArrows = true;
config.showNavigationIndicators = true;
}
}
HTML:
<ngb-carousel *ngIf="items" [showNavigationArrows]="showNavigationArrows"
[showNavigationIndicators]="showNavigationIndicators">
<ng-template ngbSlide *ngFor="let item of items">
<div class="picsum-img-wrapper">
<img [src]="item" alt="Random slide">
</div>
</ng-template>
</ngb-carousel>
我无法将图像连接到 HTML,任何帮助都会很棒。
【问题讨论】:
标签: html json angular typescript