import {
Component
} from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
volumes: any[] = [{
"id": 1,
"month": "2017-03-01"
},
{
"id": 2,
"month": "2017-04-01"
},
{
"id": 3,
"month": "2017-05-01"
},
{
"id": 4,
"month": "2017-06-01"
},
{
"id": 5,
"month": "2017-07-01"
},
{
"id": 6,
"month": "2017-08-01"
},
{
"id": 7,
"month": "2017-09-01"
},
{
"id": 8,
"month": "2017-10-01"
},
{
"id": 9,
"month": "2017-11-01"
},
{
"id": 10,
"month": "2017-12-01"
},
{
"id": 11,
"month": "2018-01-01"
},
{
"id": 12,
"month": "2018-02-01"
},
{
"id": 13,
"month": "2018-03-01"
}
];
checkYear(date) {
return new Date(date).getFullYear() == 2017 ? true : false;
}
}
.pink-color {
color: pink;
}
<table>
<tr>
<th>Line 1</th>
<th *ngFor="let volume of volumes" [ngClass]="{ 'pink-color': checkYear(volume.month) }">
{{ volume.id }}
</th>
</tr>
</table>