如何在angular typescript中自动增加参数的id?
我需要使用如何在angular typescript中自动增加参数的id?,angular,typescript,Angular,Typescript,我需要使用@ks89/angular modal gallery创建一个图库,剩下要做的就是为图库提供不同的ID。 我尝试使用for循环,但它给了我未定义的 page1.ts getAllPosts() { this.authService.getAllPosts().pipe(takeUntil(this.destroy$)).subscribe((res: any) => { const ress = res; console.log(ress);
@ks89/angular modal gallery
创建一个图库,剩下要做的就是为图库提供不同的ID。
我尝试使用for循环,但它给了我未定义的
page1.ts
getAllPosts() {
this.authService.getAllPosts().pipe(takeUntil(this.destroy$)).subscribe((res: any) => {
const ress = res;
console.log(ress);
this.getFullPosts = res.data.post;
this.personSubject.next(res.data.post)
this.userGallery = res.data.post.forEach(img => {
img.galleryImages = img.images.map(image => {
console.log(image.lenght)
return new Image(
id: //here i have to pass the id for each gallery,
{
img: image,
extUrl: image,
title: image,
})
});
});
});
}
export declare class Image {
id: number;
modal: ModalImage;
plain?: PlainImage;
constructor(id: number, modal: ModalImage, plain?: PlainImage);
}
Image.ts
getAllPosts() {
this.authService.getAllPosts().pipe(takeUntil(this.destroy$)).subscribe((res: any) => {
const ress = res;
console.log(ress);
this.getFullPosts = res.data.post;
this.personSubject.next(res.data.post)
this.userGallery = res.data.post.forEach(img => {
img.galleryImages = img.images.map(image => {
console.log(image.lenght)
return new Image(
id: //here i have to pass the id for each gallery,
{
img: image,
extUrl: image,
title: image,
})
});
});
});
}
export declare class Image {
id: number;
modal: ModalImage;
plain?: PlainImage;
constructor(id: number, modal: ModalImage, plain?: PlainImage);
}
当使用map、forEach或find over数组时,可以使用额外的参数,索引(第一个是0)
但是,确实要检查是否有必要在你的图库中输入“id”。一般来说,在a*NG中没有必要有不同的id您只需要在id中添加任意数字:?但这应该是独一无二的?我必须创建尽可能多的图库,就像我在帖子中的用户一样。。因此,每个库按其类都有一个名为id的参数,而不是html中ngfor的参数