How to divide *ngFor list of values into two divs
html<div *ngFor="let person of set1; let ind = index;">
<div *ngIf="ind % 2 == 0">
{{set1[ind]}} - {{set1[ind+1]}}
</div>
</div>
tsexport class AppComponent {
set1 = [1,2,3,4,5,6];
}
Display data from ngFor loop in two columns in Angular
Use the slice pipe With the SlicePipe https://angular.io/api/common/SlicePipe
<div class="col-md-6">
<div *ngFor="let dia of selectedCenter.dias | slice:0:5>
...
</div>
</div>
<div class="col-md-6">
<div *ngFor="let dia of selectedCenter.dias | slice:5:9>
...
</div>
</div>
*ngFor take two values at once?
Flexbox approach to achieve 2 column layout of a linear list
<div class="parent">
<div class="child" *ngFor="let point of points" >
<label for=... ></label>
<input ...></input>
</div>
</div>
.parent {
display: flex;
flex-wrap: wrap;
}
.child {
flex: 50%;
}
ngFor create 2 rows
That exists with slightly different syntax:
<template ngFor let-element [ngForOf]="data" let-i="index">
<tr>...</tr> //row 1
<tr>...</tr> //row 2
</template>
or
<ng-container *ngFor="let element of data let i=index">
<tr>...</tr> //row 1
<tr>...</tr> //row 2
</ng-container>
update for >= 4.0.0 <template>
was changed to <ng-template>
<ng-template ngFor let-element [ngForOf]="data" let-i="index">
<tr>...</tr> //row 1
<tr>...</tr> //row 2
</ng-template>
How do I reference two active ngFor s at the same time?
If you are trying to reference a property name with variable, you should parenthesize with []
.
This would work:
<table>
<tr>
<th>Name</th>
<th *ngFor="let property of addedColumns">{{property}}</th>
</tr>
<tr *ngFor="let obj of objectList">
<td>{{obj.name}}</td>
<td *ngFor="let property of addedColumns">{{obj.properties[property]}}</td>
</tr>
</table>
Related Topics
React Wait Until Set State in the Same Function
How to Disable Clicking Inside Div
Restrict to 2 Decimal Places in Keypress of a Text Box
The Create-React-App Imports Restriction Outside of Src Directory
Hiding the Address Bar of a Browser (Popup)
Regex to Get String Between Curly Braces
How to Apply CSS to Parent Using Child Selector - With CSS or Angular 2
Set Values in Input Type Date and Time in JavaScript
Onclick JavaScript to Make Browser Go Back to Previous Page
How to Bind on Click Event on Dynamically Created Button in Angular 6
React Jsx - Make Substring in Bold
Pass Input Tag Value to as Href Parameter
Multiple Key Names, Same Pair Value
How to Prevent Ajax Requests to Follow Redirects Using Jquery
Save State When Refresh Page - Reactjs
Discord.Js Deletemessage() Doesn't Work
How to Get First N Number of Elements from an Array
Localstorage Values Get Reset After Refreshing Page and Inserting New Values