Angular HTTPClient property returns property on object

  constructor(private http: HttpClient) {
  }
  ngOnInit() {
   this.http.get('url').subscribe(data => {
     console.log(data);
     console.log(data.login);
   });
  }
}

Here I can see the data logging into the console, but I get an error when the property name does not exist in the data. Is there a workaround for this without using an interface? Because the data I want to get is pretty huge and likely to change in the future, so is there a better way?

+4
source share
1 answer

docs when usingHttpClient...

 this.http.get('/api/items').subscribe(data => {
   // Read the result field from the JSON response.
   this.results = data['results'];
 });

data['results'] , . data.results, TypeScript , , HTTP, results. , HttpClient JSON Object, , .

, ( ), .

+3

Source: https://habr.com/ru/post/1688591/


All Articles