Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在angular typescript中自动增加参数的id?_Angular_Typescript - Fatal编程技术网

如何在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的参数