i can't access my files of my angular project during deployment

242 Views Asked by At

i'm trying to deploy my web application with frontend: angular
but i can't access my JSON file in assets folder

so this is the funstion to get data from JSON file

getLanguage()
  {
    let language=localStorage.getItem('language')
    if (!language)
      language = 'english'
    return this.http.get('www/dist/assets/languages/'+language+'.json')
  }
}

and this is the path of the file in my server :
enter image description here

i'm trying to access the file JSON in my server
but i can't , i don't if its' an URL problem or something else ?

2

There are 2 best solutions below

8
DeborahK On

As per the comment on your question, this should work:

return this.http.get('assets/languages/'+language+'.json')

The folder is relative to your application folder (src folder at dev time).

You also need to ensure that the assets folder is defined in the angular.json file.

Under "architect" and "build", ensure you have something that looks like this:

            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
0
Hau Nguyen On

try return this.http.get('./assets/languages/'+language+'.json')

that is add ./ before assets/