0

I am using Angular 2 to make a webpage. When I load the page, I use OnInit to run the following method (with generic names substituted):

getAllObjects(): Promise<object[]>{
    return this.http.get(this.getAllObjectsUrl).toPromise().then(response => response.json().data).catch(this.handleError);
}

I've verified in my browser that the getAllObjects url does indeed return an array of object in JSON format. Here is the url if it is helpful:

private getAllObjectsUrl : 'http://99.240.124.235:7060/REST/rest/companyService/getAllCompanies.json/';

However, this method triggers the handleError catch and the browser's debugging log shows GET localhost:3000/null 404 NOT FOUND (I am using an npm server to run it, hence the localhost).

I do not believe it is a CORS issue because I downloaded the Chrome CORS plugin and other API calls have worked. It is only this particular API url that is causing a problem, which I find strange as my other API calls work and they follow the exact same format (except a different url).

I thought maybe the appComponent wasn't allowed an OnInit, but I replaced getAllObjects() with a different working API call, and I didn't receive this error.

I am completely stuck and any help would be appreciated (could this error be because of the web API, not the front end?).

1 Answer 1

1

getAllObjectsUrl doesn't contain the url because you are using colon(:) instead of equal sign(=)

Colon indicates the type of the variable, whereas equal sign initializes it.

change this

private getAllObjectsUrl : 'http://99.240.124.235:7060/REST/rest/companyService/getAllCompanies.json/';

for this

private getAllObjectsUrl = 'http://99.240.124.235:7060/REST/rest/companyService/getAllCompanies.json/';
Sign up to request clarification or add additional context in comments.

1 Comment

That is embarrassing... I don't know why I used a colon for this one url, or how I didn't see that... thanks...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.