I would like to get results array from atom.service into atom.component. I thought I could bring in results array into atom.component with source codes below (not presented whole codes). But I found I could not access this.atoms in atom.component from source codes below. The results array in atom.service.ts was created successfully. If anyone knows about how to get access to results array in the atom.component, could you give some guide about it?
atom.service.ts
getAtoms(private newConcept: string) {
this.http.get('api/atoms.json')
.map( (responseData) => {return responseData.json()})
.subscribe( data => {
let results:Array<RAtom> = [];
for (i = 0; i < data.result.length; i++) {
results.push(new RAtom(data.result[i].classType, data.result[i].ui));
}
return results;
});
}
atom.component.ts
atoms: Array<RAtom>;
searchAtoms(newConcept: string) {
if (newConcept) {
this.atoms = this.service.getAtoms(newConcept);
}
}
RAtom.ts
export class RAtom {
classType: string;
ui: string;
constructor(classType: string, ui:string) {
this.classType = classType;
this.ui = ui;
}
}