Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access files from assets folder in angular 2?

Tags:

angular

I have some images and style sheets files inside assets folder in angular 2 app but how to access those files and images in main index.html file?

like image 362
user3869304 Avatar asked Jan 29 '17 04:01

user3869304


People also ask

Where is assets folder in angular?

The Angular application has a default assets folder. By default, whatever you put in the assets folder you can access it directly from the browser and queried through an HTTP request. You can create your own folder like assets by adding that folder to the assets section in the angular. json file.

Can we access file system in angular?

To start using the amazing File System Access API in Angular, or typescript project, you will be faced first, with unrecognized type error. Head to Typescript website and search for File System Access. The first result is the newest. @types/wicg-file-system-access.

What are assets angular?

Let's start with assets, this could be anything from images, videos, json files to styles and scripts. By default, Angular has an asset directory, located under the /src directory at the root of your angular project. This is copied over to the build directory by Angular CLI during the build process of your app.


1 Answers

You have to put your files and use the relative path from the assets folder.

For example if i put a css file in src/assets/css/myfile.css, then I have to access it like this :

<link rel="stylesheet" href="assets/css/myfile.css"> 
like image 183
marioaviles Avatar answered Oct 14 '22 11:10

marioaviles