I have made a component in the angular2+ file. I want to make an http request to the nodeJs server. However, i keep getting - >
Uncaught (in promise): TypeError: Cannot read property 'get' of undefined
TypeError: Cannot read property 'get' of undefined
To note, I am even unable to retrieve the value of the global variables stored in one function and (unable to) accessed in another function. And this is the first time i am facing it ever.
code -
app.component.ts
import { HttpClient, HttpParams, HttpRequest, HttpEvent } from '@angular/common/http';
@Injectable()
export class MachineMergerComponent implements OnInit {
constructor(private http: HttpClient) {}
onFileLoadTopFive(fileLoadedEvent) {
// -----=================== Top Five Neovis ==================== -------------
this.rhsNameTopFive = [];
this.relationshipInfo = [];
for (var i = 0; i < 5; i++) {
this.rhsNameTopFive.push(this.objectValueAfterConfidence1[i].rhs[0])
console.log("this.rhsNameTopFive = ", this.rhsNameTopFive)
// http request
var relationObj = {
'relationObj1': this.rhsNameTopFive[i]
}
}
console.log("relationObj = ", relationObj);
this.http.get("http://localhost:3003/seekRelationship?relationObj=" + this.rhsNameTopFive[0])
.map(Response => Response)
.catch((err) => {
console.log("err =", err)
return Observable.throw(err);
})
.subscribe((res: Response) => {
console.log("XXXXXXXXXXXX Response on /seekExtraction", res);
this.relationshipInfo[i] = res;
console.log(" this.relationshipInfo[" + i + "]", this.relationshipInfo[i])
})
}
}
app.module.ts
import { HttpClientModule } from '@angular/common/http';
@NgModule({
imports: [
CommonModule,
FormsModule,
// HttpModule ,
HttpClientModule,
],
declarations: [ MachineMergerComponent, ]
})
export class ApiSequenceModule { }