How To Build An Angular Custom Assets Folder

Every Angular app created with @angular/cli includes an assets folder within the src directory. And any file or folder generated within the assets folder is made public. Your options, however, are not limited to this folder. Other assets, such as directories, may be readily added by adding their paths to the angular.json file. Let’s look at an example to better grasp this.

Assume I want to create a new folder named demo within the src directory and add the JSON file below to it.

  "firstName": "Prinkesha",
  "lastName": "Lathidadiya",
  "username": "denny",
  "dateOfbirth": "30-2-2001"

We’ll name the file profile.json.

When you’ve created the folder and inserted the file, you must make Angular aware of it.

Just add the following line of code to your angular.json file beneath the assets array key to do this.

That’s all there is to it! Following that, just restart your Angular application and try to view the file using a web browser. If everything went as planned, you should see the following output in the web browser.

Submit a Comment

Your email address will not be published. Required fields are marked *


Select Categories