This is my "monthlyCalendar" object:
{
"monthName": "September 2019",
"dateObjList": {
"1": {
"dayOfWeek": "0",
"isPublicHoliday": false,
.............
},
"2": {
"dayOfWeek": "0",
"isPublicHoliday": true,
.............
},
.....................
}
}
This is my component.ts:
...........
ngOnInit() {
this.monthlyCalendarService.getMonthlyCalendar(null, null).subscribe(
(res: MonthlyCalendar) => {
this.monthlyCalendar = res;
this.monthName = this.monthlyCalendar.monthName;
},
(error: Error) => {
alert('Something wrong when getting Monthly Calendar data.\n' + error.message);
},
);
}
.........
This is my monthlyCalendarService.ts:
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { MonthlyCalendar } from './monthly-calendar';
import { Observable } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class MonthlyCalendarService {
constructor(private http: HttpClient) { }
getMonthlyCalendar(year: string, month: string): Observable<MonthlyCalendar> {
const params = new HttpParams();
params.set('year', year);
params.set('month', month);
return this.http.get('backend/getMonthlyCalendar.php', {params}).pipe(map((res: MonthlyCalendar) => res));
/*
return this.http.get('backend/getMonthlyCalendar.php', {params})
.pipe(map((res: MonthlyCalendar) =>{ console.log('service:' + JSON.stringify(res)); return res; })
//, catchError(this.handleError)
);
*/
}
}
This is my component.html:
...........
<td *ngFor="let dateObj of monthlyCalendar?.dateObjList|async" class="phCell">
<span *ngIf="dateObj.isPublicHoliday">PH</span>
</td>
...........
I want to show the span tag when the dateObj.isPublicHoliday attribute is true.
However, the browser prompts me the below error message:
ERROR Error: InvalidPipeArgument: '[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]' for pipe 'AsyncPipe'
if I apply the "keyvalue" pipe to the *ngFor also, i.e.
<td *ngFor="let dateObj of monthlyCalendar?.dateObjList|async|keyvalue" class="phCell">
I got the following error message:
Error: InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'
How can I make it works?