'How to create dynamic grid component in angular 8 and bootstrap whit row, col and list string?
I have a problem understanding how to create a grid component, which has in input of a number of columns, rows and a list of strings for the inside element of grid.
my thumbnails.component.ts
import { Component, Input } from '@angular/core';
@Component({
selector: 'thumbnails',
templateUrl: './thumbnails.component.html',
styleUrls: ['./thumbnails.component.scss']
})
export class ThumbnailsComponent{
public UrlList = ["one","two","three","four","five","six","seven","eight","nine","ten"];
private col: Number = 4;
private row: Number = 4;
}
my thumbnails.component.html
<div id="grid">
<ng-container *ngFor="let x of UrlList; let i = index">
<div class="row">
<div class="col">
{{x}}
</div>
</div>
</ng-container>
</div>
I don't know how to implement it. Can someone help me and explain it to me?
Solution 1:[1]
Another approach is the CSS way using display gird with gridTemplateColumns properties.
thumbnails.component.ts
import { Component, Input } from '@angular/core';
@Component({
selector: 'thumbnails',
templateUrl: './thumbnails.component.html',
styleUrls: ['./thumbnails.component.scss']
})
export class ThumbnailsComponent{
public UrlList =["one","two","three","four","five","six","seven","eight","nine","ten"];
grid(v) {
document.getElementById(
'grid'
).style.gridTemplateColumns = `repeat( ${v.value}, 175px)`;//Important step
}
}
thumbnails.component.css
.grid-container {
display: grid;
grid-gap: 15px;
}
thumbnails.component.html
<label>Enter Col :</label><input type="text" #col />
<button (click)="grid(col)">Set Grid</button>
<div id="grid" class="grid-container row">
<ng-container *ngFor="let x of UrlList; let i = index">
<div class="col">
{{ x }}
</div>
</ng-container>
</div>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Soham Biswas |
