1
export class EditClientComponent implements OnInit {

 apiEndPoint: 'http://localhost:1337/upload';

 fileChange(event) {
 //...
    this.http.post(`${this.apiEndPoint}`, formData, httpOptions)
 //...
 }
}

I get a weird error:

status: 404, statusText: "Not Found", url: "http://localhost:4100/undefined"...

Which means that it's not reading apiEndPoint at all, and if I replace ${this.apiEndPoint} with the actual url, it works.

What can I do?

3 Answers 3

5

change the declaration of apiEndPoint to = instead of :

apiEndPoint = 'http://localhost:1337/upload';

you are specifying the type of the variable not an initial value.

Sign up to request clarification or add additional context in comments.

Comments

1

In addition to the above reply. You don't need to format a string if you already have the full value of the URL in the var. Instead of this: ${this.apiEndPoint}. Simply do:

this.http.post(this.apiEndPoint, formData, httpOptions)

Comments

1

In here apiEndPoint: 'http://localhost:1337/upload'; is statement of declare the type of apiEndPoint to string literal and it is initial value is undefined.

Just fixed to this

apiEndPoint:string = 'http://localhost:1337/upload';

Comments

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.