My Angular-based todo application has encountered an error notification from the system

Every time I try to post something, the system responds with a 405 error message in the console. I'm not sure what caused this issue or how to resolve it.

Alternatively, if I click the done button, the console displays a 500 error message.

Here is the HTML code snippet:

<input
  (keyup.enter)="createPost(name)" #name
  type="text" class="form-control">
<ul class="list-group">
  <li
  *ngFor="let post of posts"
  [ngClass]="post.completed?'list-group-item list-group-item-success':'list-group-item'">
  <button
    (click)="updatePost(post)"
    class="btn btn-outline-success btn-sm" id="button">
    {{ post.completed ? 'Done' : 'Not ready' }}
  </button>
  <button
    (click)="deletePost(post)"
    class="btn btn-outline-danger ml-2 btn-sm">
    Delete
  </button>
  {{ post.name }}
  </li>
</ul>

And here is the TypeScript code:

export class ToDoAppComponent {
  posts: any;
  private url = 'http://todoapp.test/api';

  constructor(private http: HttpClient) {
    http.get(this.url).subscribe(response => {
      this.posts = response;
    });
  }



  createPost(input: HTMLInputElement) {
    // tslint:disable-next-line: prefer-const
    let post: any = { name: input.value }
    input.value = '';

    this.http.post(this.url, JSON.stringify(post)).subscribe(response => {
      post.id = response.id;
      this.posts.splice(0, 0, post);

    });
  }

  updatePost(post) {
    this.http.put(this.url + '/' + post.id, JSON.stringify({ status: !post.status })).subscribe(response => {
      post.status = !post.status;

    });
  }

  deletePost(post) {
    this.http.delete(this.url + '/' + post.id, ).subscribe(response => {
      let index = this.posts.indexOf(post);
      this.posts.splice(index, 1);
    })
  }
}

Here are the error message screenshots and the server's response data: https://i.sstatic.net/vuk3z.jpghttps://i.sstatic.net/V96FV.jpg https://i.sstatic.net/zwvYr.jpg

Answer №1

Implementing a new CORS policy on the backend to fix the 405 problem

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Incorporating Bloodhound into an Angular 2 CLI project

I have been working on integrating Bloodhound.js into an Angular 2 project that utilizes Angular 2 CLI. Currently, I have successfully implemented jQuery by following these steps: Installed jQuery using npm install jquery --save Installed jQuery Type ...

Encountering difficulties resolving the dependency tree for an angular-ionic project

Node version: v16.3.0 ng version: 12.1.0 Currently working on an Angular-Ionic 5 project Encountered an error while running the npm install commandhttps://i.sstatic.net/nYOJc.png 2. Also tried running npm install --force but faced a different error h ...

SweetAlert2 not displaying properly in Ionic6 - troubleshooting the issue

My current project is an Ionic 5 Angular project with SweetAlerts2 popups. Recently, I decided to upgrade to Ionic6 and encountered an issue where the SweetAlerts2 popups are not displaying correctly. The alert seems to only show up in the header, leaving ...

What is the best way to modify an existing object in an Observable Array in Angular?

As I work on my Ionic 5 / Angular application, a challenge arises when attempting to update a Conversation object within the existing array of Conversation: private _conversations = new BehaviorSubject<Conversation[]>([ new Conversation( & ...

What are the benefits of incorporating a proxy.conf.json file into an Angular application?

Imagine we have a server running on http://localhost:8080/. Rather than configuring the back-end's base URL from environment.ts file, we can create a proxy.conf.json file with the code below: { "/api": { "target": "http://localhost:8080", ...

Utilizing Angular HTTP Interceptor to Show Loading Spinner Across Multiple Modules

My goal is to utilize the ng4-loading-spinner spinner when making HTTP calls to my API. I referred to the examples provided in the following resources: Angular Guide on Intercepting HTTP Requests/Responses Stack Overflow Post on Using HttpClient Interce ...

Working with Typescript: Defining the return type of a function that extracts a subset of an object

Currently, I am attempting to create a function that will return a subset of an object's properties. However, I’m facing some issues with my code and I can't pinpoint the problem. const initialState = { count: 0, mounted: false, } type St ...

Navigating through diverse objects in Typescript

My challenge involves a state object and an update object that will merge with the state object. However, if the update value is null, it should be deleted instead of just combining them using {...a, ...b}. const obj = { other: new Date(), num: 5, ...

Exploring the features of the window object in an Angular application compiled ahead of time

In an effort to streamline our development process and avoid having to build the Angular-App multiple times for different environments, we decided to skip injecting environment-specific variables (such as service endpoints) into our app using regular file ...

Determining When to Activate Button Based on Angular - Verifying That All Choices Have Been Ch

This quiz application requires the user to choose options before proceeding to the next page, with the next button being disabled by default. Once all options are chosen, the next button should become enabled. NOTE: Although the functionality for selecti ...

Angular 2: A ready-made solution for developing interactive discussion features

Currently working on my Angular 2 application and looking to incorporate a discussion feature. Are there any pre-existing solutions available for this integration? ...

Visibility issue with Angular 4 ngFor variable within specific child component

I'm facing an unusual issue that I need help with. I am using a simple ngFor loop in my template code and for some reason, the variable I am trying to access is visible everywhere inside the loop except for one particular subcomponent. It's stran ...

Exploring the power of Async/Await with Angular 5 HttpClient and forEach

I am struggling to implement async/await in my code to show a spinner when I click on a button and hide it once I have all the data. Below is a simplified version of what I have: .ts: isLoading: boolean = false; onLoad() { this.isLoading = true; ...

problem encountered when running "ionic cordova build android --prod --release"

A chat application has been developed using Ionic2. Upon attempting to generate a production build with ionic cordova build android --prod --release, the following error is encountered. Error: ./node_modules/rxjs/observable/BoundCallbackObservable.js ...

Unable to send a function as props to a child component in TypeScript

Within my application, I have a parent component that holds a state and a setState function. This state and function are then passed down to a child component in order to retrieve values (such as input field data). When the function is triggered in the chi ...

What is the process for performing interpolation in Angular version 8?

In my Angular project, I have 2 components working together. Component A sends an id using the following code snippet: <a [routerLink]="['/numbersbyareacode', element.id]"> {{element.title}} </a> Upon navigating to Component B, ...

Angular click switch Component keeps track of its previous state

I recently developed an Angular component that consists of a button and an icon. One key requirement is for each instance of this component to retain its own status. For example, let's say we have three instances in the app.component.html: <app-v ...

Custom input in Angular 2 rc.5: Form control is missing a value accessor for an unspecified name

My custom input component is designed as follows: import {Component, Provider, forwardRef} from "@angular/core"; import {ControlValueAccessor, NG_VALUE_ACCESSOR} from "@angular/forms"; const noop = () => {}; const CUSTOM_INPUT_CONT ...

Allowing cross-origin resource sharing (CORS) in .NET Core Web API and Angular 6

Currently, I am facing an issue with my HTTP POST request from Angular 6. The request is successfully hitting the .net core Web API endpoint, but unfortunately, I am not receiving the expected response back in Angular 6. To make matters worse, when checkin ...

Unexpected behavior: Promise.catch() fails to catch exception in AngularJS unit test

During the process of writing Jasmine unit tests for my Typescript app and running them via Resharper, I encountered an issue with executing an action when the handler throws an exception: describe("Q Service Test", () => { var q: ng.IQService; ...