angular

Access to XMLHttpRequest has been blocked by CORS policy

南楼画角 提交于 2021-02-18 09:08:29
问题 I've a problem when I try to do PATCH request in an angular 7 web application. In my backend I have: app.use((req, res, next) => { res.set({ "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Methods": "*", "Access-Control-Allow-Headers": "'Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token'", }); next(); }); In my frontend service, I've: patchEntity(ent: any, id) { let headers = new Headers({ 'Content-Type': '*' }); let options = new RequestOptions({ headers: headers });

Access to XMLHttpRequest has been blocked by CORS policy

喜欢而已 提交于 2021-02-18 09:04:08
问题 I've a problem when I try to do PATCH request in an angular 7 web application. In my backend I have: app.use((req, res, next) => { res.set({ "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Methods": "*", "Access-Control-Allow-Headers": "'Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token'", }); next(); }); In my frontend service, I've: patchEntity(ent: any, id) { let headers = new Headers({ 'Content-Type': '*' }); let options = new RequestOptions({ headers: headers });

Merge two observables, single output

好久不见. 提交于 2021-02-18 09:02:01
问题 Hello guys Im trying to grasp RxJS lib and the whole idea of reactive programming. Im trying to merge two observables into one. First observable contains array of objects DefectImages[] the second observable contains array of strings, which then I convert to array of DefectImages[] . After that I would like to merge these two observables into one. Below my code: const observable = CachedPhotosBuffer.getInstance().asObservable() .pipe( switchMap(data => { return data.map((url) => DefectImage

Merge two observables, single output

妖精的绣舞 提交于 2021-02-18 09:01:41
问题 Hello guys Im trying to grasp RxJS lib and the whole idea of reactive programming. Im trying to merge two observables into one. First observable contains array of objects DefectImages[] the second observable contains array of strings, which then I convert to array of DefectImages[] . After that I would like to merge these two observables into one. Below my code: const observable = CachedPhotosBuffer.getInstance().asObservable() .pipe( switchMap(data => { return data.map((url) => DefectImage

angular ng serve command throws error: An unhandled exception occurred: Project does not exist

末鹿安然 提交于 2021-02-18 08:52:12
问题 I am trying to up my local angular dev env using ng serve, it was working perfectly fine a day back, but now every time I run ng serve or npm start it throws an error: "An unhandled exception occurred: Project does not exist." I have tried running ng serve in one of my different project, it works there. not sure what it causing this error 回答1: Make sure the name of the project in your angular.json matches what is being called from your package.json scripts section. This is how I discovered

Angular 6 - How to extract translation from typescript

别来无恙 提交于 2021-02-18 08:34:09
问题 I am using Angular 6 and I have setup handling of translations according to the documentation found here: https://angular.io/guide/i18n. The problem is that the documentation does not explain how to get translations using typescript. There is a similar question here: Can I use Angular i18n to translate string literals in typescript code But i cannot use that answer since it relies on ngx-translate which will be deprecated once Angular catches up, see https://github.com/ngx-translate/core

response redirection(302) not work in angular

旧城冷巷雨未停 提交于 2021-02-18 08:05:25
问题 I Designed a login page for SSO(Single Sign-On) by angular and the services for login developed separately by spring boot framework. In the angular app, when submitted login form, login service call with post-HttpMethod by HttpClient module. In login service if username and password be correct then in the result of login service, set response status to 302 and add a specific URL to the header of the response. in this scenario I expect to browser redirect to specific URL, but this is not

response redirection(302) not work in angular

拜拜、爱过 提交于 2021-02-18 08:05:07
问题 I Designed a login page for SSO(Single Sign-On) by angular and the services for login developed separately by spring boot framework. In the angular app, when submitted login form, login service call with post-HttpMethod by HttpClient module. In login service if username and password be correct then in the result of login service, set response status to 302 and add a specific URL to the header of the response. in this scenario I expect to browser redirect to specific URL, but this is not

Angular 2 - Dynamic routing from JSON data

有些话、适合烂在心里 提交于 2021-02-18 07:56:29
问题 In Angular 2.0 stable, I have a application in which I have to define/config routes based on JSON data I receive. I don't have any predefined routes.I am getting this data in the constructor of my bootstrap component. How can i achieve that? Is it possible? 回答1: The way that I achieved this was to load the routes before bootstrapping the angular app. This way when the app starts all the dynamic routes are already there. So you have to load all the routes in the main.ts file before the

Angular 6 httpClient Post with credentials

柔情痞子 提交于 2021-02-18 06:40:49
问题 I have some code which posts some data to create a data record. It's in a service: Here's the code: import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) }; @Injectable({ providedIn: 'root' }) export class ApiService { constructor(private http: HttpClient) { } create() { const postedData = { userid: 1, title: 'title here', body: 'body text' }; return