Accessing files outside project folder

2019-03-02 11:16发布

问题:

I am working on an angular 5 application where I am having some issues access some files. Let me give show you how my project is set up so you can see the issue.

  • root
    • desired_files
    • angularApp
    • app_generating_files

So my issue is I need to be able to access the files in the desired_filesfolder from my angular application. The files that go into this folder are generated by the other project also in my root. If you have any ideas on how I can do this it would be greatly appreciated.

(I am using Docker, on the app_generating_files project, so I'm not sure if it would be a good idea to try and use that)

回答1:

The beginning to the answer you're looking for is here : Angular-cli: How can I access images outside of the assets folder

In the glob object, be sure to add allowOutsideOutDir :

{
  "glob": "**/*",
  "input": "../../path/to/files",
  "output": "./assets/outside-assets",
  "allowOutsideOutDir": true
}

For example, if you have an image named test.jpg in the directory '../../path/to/files' you can include it in your project using the markup

<img src="assets/outside-assets/test.jpg" alt="not found">

Make sure the local version of your ng-cli is 1.5.0 as newer versions don't support allowOutsideOutDir as discussed here https://github.com/angular/angular-cli/issues/8783