javascript - Ngu-Carousel Angular 7:尝试从 json 导入数据
问题描述
我正在尝试从 json 导入数据并使用 ngu-carousel 显示它。我可以正确显示它,但它显示此错误。
然后在我尝试单击上一个/下一个按钮后,它显示此错误。
这是我的代码。
图库.component.ts
import { Component, OnInit } from "@angular/core";
import { NguCarouselConfig } from "@ngu/carousel";
import { ShopService } from "../shop.service";
@Component ({ selector: "app-gallery", templateUrl: "./gallery.component.html" })
export class GalleryComponent implements OnInit {
public product: any;
public carouselImg: NguCarouselConfig = {
grid: { xs: 1, sm: 2, md: 3, lg: 3, all: 0 },
slide: 1,
loop: true,
speed: 250,
point: {
visible: true,
},
load: 2,
velocity: 0,
touch: true,
};
constructor (private sv: ShopService) {};
ngOnInit () {
this.sv.getProducts().subscribe(data => {
this.product = data;
});
};
}
图库.component.html
<ngu-carousel #imgCarousel [inputs]="carouselImg" [dataSource]="product">
<ngu-tile *nguCarouselDef="let item">
<mat-card>
<mat-card-header>
<mat-card-title>{{item.name}}</mat-card-title>
</mat-card-header>
<img mat-card-image [src]="item.photo" alt="">
<mat-card-content>
<p>
{{item.remark}} <span><a href="">More info</a></span>
</p>
</mat-card-content>
</mat-card>
</ngu-tile>
<button NguCarouselPrev class="leftRs"><</button>
<button NguCarouselNext class="rightRs">></button>
</ngu-carousel>
我不知道我的代码有什么问题。我希望你们能帮助我:)
解决方案
我正在将我的工作版本与您的进行比较。尝试将其添加到您的组件中:
@ViewChild('imgCarousel') imgCarousel: NguCarousel<any>;
还要添加一个默认值,否则可能会在开始时导致问题:
public product = [];
推荐阅读
- javascript - Express.js - 在应用程序级中间件中访问目标路由详细信息
- sass - 如何连接 Sass @include 函数
- excel - 如何应用动态数字格式?
- javascript - 如何在反应中更改数组的某些值
- python-3.x - 我正在 python 的街机库中制作一个文本框。当文本长度增加超过允许的宽度时,我无法处理滚动
- jquery - 这个 jQuery 代码中的 $({ counter: 0 }) 是什么?什么类型的选择器?
- php - 合并和查找两个关联数组的总和 - PHP
- git - 在纱线工作区中运行“git clean -xdf”时,跟踪文件被删除
- apache-pig - 为什么 Pig 不能接受将整数转换为 chararray
- swift - 推送通知不能完全工作,除非绑定到 Xcode