I have encountered a problem where I am trying to post a URL using a REST API call. This functionality was working perfectly fine in Angular 1.6, but I am facing

When trying to post a URL with Angular 7 to the server, I encountered an error stating "blocked by CORS policy," although it worked fine in Angular 1.6.

The issue is related to CORS policy blocking access to XMLHttpRequest. The response to preflight request does not pass the access control check because it does not have an HTTP OK status.

return this.http.post<Driver>(url, this.emailAttributeObject, {
                    headers : new HttpHeaders({
                        'Content-type' : 'application/json'
                    })
                })
                    .pipe(
                        catchError(this.handleError('driverDetails', driverDetails))
                    );

component file:
this.myDataService.sendEmail(this.driverDetails, this.initialValue)
            .subscribe((response : Driver) => {
                    //this.driverDetails = response;
                }, error =>
                    this.toastr.error(error.message,"Problem to send Email")
            )

service file:
return this.http.post<Driver>(url, this.emailAttributeObject, {
                    headers : new HttpHeaders({
                        'Content-type' : 'application/json'
                    })
                })
                    .pipe(
                        catchError(this.handleError('driverDetails', driverDetails))
                    );

Answer №2

When working in a development environment, it is possible to turn off web security measures. To do this in Chrome, enter the following command:

chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security

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

Trouble with invoking a function within a function in Ionic2/Angular2

Currently, I am using the Cordova Facebook Plugin to retrieve user information such as name and email, which is functioning correctly. My next step is to insert this data into my own database. Testing the code for posting to the database by creating a func ...

The Component TSX is reporting a Type error stating that the Property 'onChange' is not present in the type '{ key: string; value: Model; }' as required by Props

While running the following command: npm run build I encountered an error that needs resolution: /components/Lane.tsx:37:18 Type error: Property 'onChange' is missing in type '{ key: string; value: StepModel; }' but required in type &a ...

When the *ngFor directive disrupts the CSS Grid Layout, resulting in all items being displayed in a single column

I am a beginner in the world of programming and web development. Currently, I am working on building my own personal website. My goal is to arrange boxes in a grid with 4 columns, similar to the layout you can find at this link: Each box represents an ob ...

The issue of duplicate items being stored in an array arose when inserting a new element

I am new to angular and currently working on an application that allows users to take notes and store them in a database. However, I have encountered a problem during the note addition process. When there are no existing notes in the database and I add tw ...

How can I customize the color of the disabled state in a mat-slide-toggle?

I am trying to customize the disabled state color of a mat-slide-toggle. This is what my slide toggle currently looks like: https://i.sstatic.net/Lhz0U.png Here is the code I have been using: <div> <mat-slide-toggle>Slide me!</mat-slide ...

Encountered Issue: Input of type 'number' cannot be assigned to an argument expecting type 'string'

In my React TypeScript project, I am utilizing the React Player library and a Material UI volume slider to control the volume of the video player. The volume value ranges from 0 to 1, so I created a function to calculate the value based on the slider inpu ...

Is there a way to make a TypeScript function accessible in intellisense from a JavaScript file?

I recently started learning TypeScript and I must say, I am really enjoying it. However, I have encountered a small issue. When I try to type in a JavaScript file, such as a function from my TypeScript file, it doesn't show up in intellisense. Does an ...

Angular 2 and TypeScript: Mastering Checkbox Data Binding

Below is the HTML view in which user roles are checked. I want to bind a table of modified user roles using the actualizeRoles() method. How can I achieve this? <md-accordion class="example-headers-align"> <md-expansion-panel hideToggle=" ...

Aligning two identical components within the same container when triggered by a single click

Currently, I am exploring Angular 2 and Typescript and have been developing a pager component for a table. The pager functions correctly, but I have encountered an issue with having two pagers - one above the table and one below it. When the next button on ...

What could be the reason for receiving an HttpErrorResponse when making a GET request that returns byte data

When using these headers, the API returns byte data as a response. let headers = { headers: new HttpHeaders({ 'Content-Type': 'application/octet-stream', 'responseType':'arraybuffer' as 'js ...

"Upon loading the page, I encounter JavaScript errors related to Angular's ngOnInit function. However, despite these errors,

I have a page in angular where I am loading data in the ngOnInit function. The data loads correctly and is displayed on the page, everything seems to be working fine. However, I am encountering numerous javascript errors in the console stating cannot read ...

The form validation feature in Element UI is having issues when used with the Vue 2 Composition API

I am currently developing a form that utilizes element UI's form validation within the vue 2 composition API environment. This form includes a table nested inside, making its structure somewhat complex. ... <div> <el-form ref=" ...

Creating a rotating circle in CSS with ion-slides: A step-by-step guide

Hello, I am attempting to develop a circular object that will rotate in the direction it is dragged. Within this circle, there are elements positioned along the border so that these elements also spin accordingly. To illustrate, below are the specific elem ...

The function is not properly defined for the provided service

I am facing an issue with a service that is provided in app.module.ts and injected into an exported function within the same module. Despite this setup, when running the code inside MSALInstanceFactory, it is indicating that the service is undefined. impor ...

using angular and firestore to grant public reading permission for a document

As a student developer, I recently integrated Firestore into my Angular app and encountered some challenges with the security rules. My goal: I want to display a Firestore document in an Angular view using template binding. The document should be visible ...

"encountered net::ERR_NAME_NOT_RESOLVED error when trying to upload image to s3 storage

I am currently developing an application using Angular. I have been attempting to upload a picture to my S3 bucket, but each time I try, I encounter this error in the console. https://i.stack.imgur.com/qn3AD.png Below is the code snippet from my upload.s ...

Error TS2322: Type 'Partial<T>' is not assignable to type 'T'

I'm struggling to articulate my problem, so I think the best way to convey it is through a minimal example. Take a look below: type Result = { prop1: { val1: number, val2: string }, prop2: { val1: number } }; f ...

What are the steps to incorporate a 3D scene into a React website?

Can I get some advice on how to create a React web application using TypeScript? I want to be able to click a button and have it show a new page with a scene of a town. What is the best way to achieve this in my React project? I've heard about using R ...

Is there a way for me to directly download the PDF from the API using Angular?

I'm trying to download a PDF from an API using Angular. Here's the service I've created to make the API call: getPDF(id:any) { return this.http.get( `url?=${id}`, { responseType: 'blob' as 'json', obs ...

What are some techniques for creating an HTML element that remains fixed on the page after scrolling past a certain height, even though it is originally part of

I am trying to achieve a specific effect with a <section></section> element on my web page. Once the user scrolls past the section, I want it to remain fixed at the top of the screen even as they continue scrolling downwards. This is in an Ang ...