import { Injectable } from '@angular/core';
export class Test {
public id: number; public name: string; public fid: number
};
export const TESTS2: Test[] = [
{id: 1, name: 'Lion', fid: 1},
{id: 2, name: 'Tiger', fid: 1},
{id: 3, name: 'Bear', fid: 1},
{id: 4, name: 'Wolf', fid: 1},
{id: 5, name: 'Fox', fid: 2},
{id: 6, name: 'Panda', fid: 2},
{id: 7, name: 'Kangaroo', fid: 2},
{id: 8, name: 'Giraffe', fid: 2},
{id: 9, name: 'Zebra', fid: 3},
{id: 10, name: 'Horse', fid: 3},
{id: 11, name: 'Llama', fid: 3},
{id: 12, name: 'Squirrel', fid: 3}];
let testsPromise2 = Promise.resolve(TESTS2);
@Injectable()
export class TestService2 {
getTests(id) {
let items: Test[] = [];
for(var i = 0; i < TESTS2.length; i++) {
if(TESTS2[i].fid == id) {
items.push(TESTS2[i])
}
}
return testsPromise2;
}
}
I am encountering an issue where TESTS is not accessible within the getTests function, however, testsPromise can be accessed as I receive all data if I return testsPromise in the getTests function. Why is this happening?