0

I am writing an Angular application that runs along a NodeJs app. The NodeJs app watches a folder called gallery inside the Angular app folder. The idea is that when an image is added to the gallery folder, it should be added to an image slideshow running as part of the Angular app.

Because the app is served in memory, when the image is added to the slideshow, it 404s. I have to kill ng serve and restart it in order for the image to load. I'd like to see the image actually load into the slideshow without me having to kill ng serve and restart it.

Is there a workaround to this?

The gallery folder is part of the assets folder in the cli config and it does get copied over. It's only when adding files to this folder while the ng serve is running that the image fails to load.

Thanks!

cgatian
  • 22,047
  • 9
  • 56
  • 76
vdiaz1130
  • 301
  • 1
  • 3
  • 13
  • You need to create an API service that will return the contents of the asset folder – cgatian Nov 08 '17 at 01:51
  • I have an express route in Node that returns the contents of the folder to the Angular App. – vdiaz1130 Nov 08 '17 at 01:56
  • Sorry I wasnt thinking right about this. – cgatian Nov 08 '17 at 02:20
  • 1
    This is not the intent for the assets folder. The assets are only meant to be static assets that get updated at build time (ng build or ng serve). I would upload the images to a different directory outside of angular and fetch them from there in your angular app. – LLai Nov 08 '17 at 04:16
  • I ended up doing what @LLai recommended. Thanks! – vdiaz1130 Nov 23 '17 at 21:45
  • @vdiaz1130 can you shard how you got this working using a directory outside of angular? I am asking a very similar question here: https://stackoverflow.com/questions/47880056/accessing-files-outside-project-folder – rpascal Dec 19 '17 at 20:36

1 Answers1

1

Open angular-cli.json and edit the assets properties of your app.

 "assets": [
    "assets",
    "favicon.ico",
    { "glob": "**/*", "input": "./assets/gallery", "output": "./assets/gallery" }
  ],

Webpack will still need to recompile these assets, but at least you don't have to start and stop the app.

Angular CLI Documentation

cgatian
  • 22,047
  • 9
  • 56
  • 76