Issue
in my Angular Frontend I have environment.ts like this ~~~~~~`
export const environment = {
production: false,
apiUrl: 'http://127.0.0.1:8000'
};
and my data.service.ts like this
export class DataService {
constructor(private http:HttpClient) {}
registerUser(data: any) {
return this.http.post(environment.apiUrl+'/api/register/', data);
}
}
but when I try to run the project it is encountrd following error msg
Error: src/app/service/data.service.ts:17:39 - error TS2339: Property 'apiUrl' does not exist on type '{}'.
17 return this.http.post(environment.apiUrl+'/api/register/' data);
Solution
One of the reasons can be that all the environment
do not have the same property names.
Another workaround for this issue, is by assigning any type. Like shown below
return this.http.post((environment as any).apiUrl+'/api/register/' data);
Answered By - Naren Murali
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.