skip to Main Content

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

Answers


  1. 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"
                ],
    
    Login or Signup to reply.
  2. try
    return this.http.get('./assets/languages/'+language+'.json')

    that is add ./ before assets/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search