@asifaathwal wrote:
i am developing a hybrid live streaming app in ionic4. i have to load remote data from json to get url of my chennal for live streaming. I am using http method to get data from json but i am getting error of “No ‘Access-Control-Allow-Origin’ header is present on the requested resource.” So that’s why i am using CORS policy of IONIC to avoid this error. But now i am facing error of " Types of property ‘headers’ are incompatible. [ng] Type ‘Headers’ is not assignable to type ‘HttpHeaders | { [header: string]: string | string; }’. [ng] Type ‘Headers’ is not assignable to type ‘{ [header: string]: string | string; }’. [ng] Index signature is missing in type ‘Headers’."
I am using http method to get data from json but i am getting error of “No ‘Access-Control-Allow-Origin’ header is present on the requested resource.” So that’s why i am using CORS policy of IONIC to avoid this error.
Function to load data:##
reddit-data.Service.ts:##
getRemoteData(){const headerDict = { 'Content-Type': 'application/json', 'Accept': 'application/json', 'Access-Control-Allow-Headers': 'Content-Type',}const requestOptions = { headers: new Headers(headerDict), }; this.http.get("url" ,requestOptions).subscribe((res) => { //console.log(data); err=>{console.log(err)}});}
homepage.ts###
ngOnInit() { this.redditService.getRemoteData(); }
I am getting error of header:###
[ng] ERROR in src/app/services/reddit-data.service.ts(56,75): error TS2345: Argument of type ‘{ headers: Headers; }’ is not assignable to parameter of type ‘{ headers?: HttpHeaders | { [header: string]: string | string; }; observe?: “body”; params?: HttpParams | { [param: string]: string | string; }; reportProgress?: boolean; responseType?: “json”; withCredentials?: boolean; }’. [ng] Types of property ‘headers’ are incompatible. [ng] Type ‘Headers’ is not assignable to type ‘HttpHeaders | { [header: string]: string | string; }’. [ng] Type ‘Headers’ is not assignable to type ‘{ [header: string]: string | string; }’. [ng] Index signature is missing in type ‘Headers’.
Posts: 1
Participants: 1