0

I have to create this particular layout in Angular 9. enter image description here

I am using the ngx-masonry package. (https://www.npmjs.com/package/ngx-masonry) to create this particular grid.

My code is as follows : For html component

<div class="container pt-5">
    <ngx-masonry>
        <div ngxMasonryItem class="masonry-item" *ngFor="let item of masonryItems">
            <img src="{{ item.src }}">
       </div>
    </ngx-masonry>
</div>

For ts component

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-inspirations',
  templateUrl: './inspirations.component.html',
  styleUrls: ['./inspirations.component.css']
})
export class InspirationsComponent implements OnInit {
  masonryItems = [
    {src: "../../assets/component_7_images/image1.png"},
    {src: "../../assets/component_7_images/image2.png"},
    {src: "../../assets/component_7_images/image3.png"},
    {src: "../../assets/component_7_images/image4.png"},
    {src: "../../assets/component_7_images/image5.png"},
    {src: "../../assets/component_7_images/image6.png"},
    {src: "../../assets/component_7_images/image7.png"}
  ];

  constructor() { }

  ngOnInit(): void {
  }

}

The result I am getting is :

enter image description here

I need the pictures in a proper masonry format. Can someone guide ?

1 Answers1

0

you need to give your items width value either a percentage or hard coded value like:

    @Component({
  selector: 'my-component',
  template: `
     <ngx-masonry>
       <div ngxMasonryItem class="masonry-item" *ngFor="let item of masonryItems">
        {{item.title}}
      </div>
     </ngx-masonry>
     `,
  styles: [
    `
      .masonry-item { width: 200px; }
    `
  ]
})
class MyComponent {
  masonryItems = [
    { title: 'item 1' },
    { title: 'item 2' },
    { title: 'item 3' },
  ];
}