0

On the following Blitz, when trying to hit a blob storage API I get the following error in the console:

ERROR
Error: Cannot set property 'id' of undefined**

I suspect the error has to do where the way I'm writing the service, maybe I should use BehaviorSubject instead of an HTTPClient and then parse the xml as json object. Or maybe it has to do with the async call. The point is the icon gets created when this.fileservice.add() is inside the ngOnInit function.

ngOnInit() {

  this.getAzureFiles();

  this.fileService.add({ Name: 'File 7', isFolder: false, parent: 'root' });

  this.updateFileElementQuery();
} 

so inside that function I'm just replacing it with the parsed response from azure, this should work. However it gives me the above error.

Basically I need the blob API to show as icons on my frontend.

halfer
  • 19,824
  • 17
  • 99
  • 186
brohymn
  • 460
  • 5
  • 22
  • In `getAzureFiles`, the line `this.fileService.add(this.azureFiles);` should be inside of the subscribe callback, after the call to `anotherFunction`. In your original code, you try to use `this.azureFiles` before it has been set. See [this stackblitz](https://stackblitz.com/edit/github-kfhnmh-tce7q1). – ConnorsFan Sep 21 '18 at 22:17
  • Possible duplicate of [How do I return the response from an Observable/http/async call in angular2?](https://stackoverflow.com/questions/43055706/how-do-i-return-the-response-from-an-observable-http-async-call-in-angular2) – ConnorsFan Sep 21 '18 at 22:18
  • yeah. I did that, but as you can see the icon is not showing. an icon only shows if the **this.fileService.add(whatever)** is outside the subscribe function – brohymn Sep 21 '18 at 22:22
  • I see a "Folder A" icon. Is that the icon that you are talking about? – ConnorsFan Sep 21 '18 at 22:23
  • the folder A icon is hardcoded , see line 32 inside ngOnInit – brohymn Sep 21 '18 at 22:24
  • No, the solution should show a file icon with **"tex1.txt"** as its name. folder A is hardcoded on line 32 – brohymn Sep 21 '18 at 22:31

1 Answers1

1

You have to move fileService add function call inside the subscribe and call this.updateFileElementQuery() right after that line.

You can find the solution here

gr4viton
  • 1,434
  • 1
  • 8
  • 21