So getallaccounts() calls and returns from a service via http.get(‘address’)…I’m getting that RES has no length.. I am getting back an array…confused….
ngOnInit() {
this.requestService.getAllAccounts().subscribe(
(res) => {
//var jsonres = res.json();
for (let i = 0; i < res.length; i++) {
for (let j = 0; j < res[i].passwords.length; j++) {
let theTime = new Date(res[i].passwords[j].expiryDate).getTime();
let theNow = new Date().getTime();
let difference = theTime - theNow;
if (difference <= 2592000) {
if (difference <= 0) {
res[i].passwords[j].classcolor = "red";
} else {
res[i].passwords[j].classcolor = "yellow";
In the console I console.log out the RES and see
(113) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…},
{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…},
{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…},
{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…},
{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…},
{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…},
{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…},{…},
{…}, {…}, {…}, {…}, …]
[0 … 99] 0 : {id: 91, title: ‘People Soft’,
description: ‘People Soft’, isActive: ‘Y’, isRetired: ‘N’, …} 1 :
{id: 92, title: ‘PGP Universal Server Administrator’, description:
‘PGP Universal Server Administrator’, isActive: ‘Y’, isRetired: ‘Y’,
…}
10
I had to cast the Observable to Array and the loop and the push to the front end took fine….
for (let i = 0; i < (res as Array<Object>).length; i++) {