Path to images not working in my Angular 4 file

image not loading in angular 8
angular get all images from folder
angular 6 assets/images
angular assets path
how to upload image in assets folder in angular 6
image path from assets in angular
angular relative path to assets
image not showing in angular 2

I am a beginner in learning angular 4 framework and have seen all the threads regarding this problem on stackoverflow but the solutions given in them not able to solve my problem.

I am getting this error "http://localhost:4200/src/assets/images/1.jpg 404 (Not Found)" .All other things are working fine but only image is not getting loaded. I am giving my .angular-cli.json code and my custom made component code where i given my img tag.

My custom component code:-

import { Component } from '@angular/core';

    template:`<button (mousemove)="clicked($event)">{{name1}}</button>
                <div *ngIf="applyDiv==false">WTF</div>
                    <li *ngFor="let i of a;let j=index">{{j}}.{{i}}</li>

                <img src="../../src/assets/images/1.jpg" alt="Ms dhoni" width="2000" height="2000"/>
                <input type="text" name="Sahil" value="sahil"/>
                <div [class.myClass]="myclass">Apply Class</div>
                <div [style.color]="applyBlue?'blue':'yellow'">Starting Angualr</div>`,


export class HelloComponent {
   // name1:string="sahil";

My code .angular-cli.json:-

  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "my-app"

  "apps": [
      "root": "src",
      "outDir": "dist",
      "assets": [

      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
      "scripts": [],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/"
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
  "lint": [
      "project": "src/",
      "exclude": "**/node_modules/**"
      "project": "src/tsconfig.spec.json",
      "exclude": "**/node_modules/**"
      "project": "e2e/tsconfig.e2e.json",
      "exclude": "**/node_modules/**"
  "test": {
    "karma": {
      "config": "./karma.conf.js"
  "defaults": {
    "styleExt": "css",
    "component": {

Can anyone tell me what is the problem here. Thanks in advance!!

You are supposed to put images in the assets folder that is inside src folder then you can specify path as assets/../image.png

Images not loading in Angular 2, In the Angular project, you don't have to add the relative path from your file to image file. Angular resolves this problem for you, and in a component, you have to  Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Angular 2\4 assets path files not found

Assuming that your HelloComponent is inside the "src > app" folder, the following tag should display the image:

<img src="../../assets/images/1.jpg" 
          alt="Ms dhoni" 
          width="2000" height="2000"/>

If it still doesn't show, then if you are using an IDE fir development, drag the image from the assets folder and drop it in one of the .html file inside tge app folder. Check the image src path there.

Images not loading from assets folder in Angular, I am still having this issues. There are no special characters in my file path except "_", image is inside assets/img folder. I see it in the dist for  I'm new to angular and I'm facing the same problem in my app where the local version works perfectly great whereas the github deployment breaks all the URLs for images. My images are placed in src/assets/xyz.jpg directory and I have tried changing the base href as well as my image url and still the image appears to be broken. I'm using angular 6.

Try increasing the dimensions of the image in paint. I had an image in the path src/assets/Library/Images with dimensions 60 x 45 which did not load and an image with dimensions 225 x 225 which loaded successfully. Hope this helps !

Assets/Images not being served · Issue #9852 · angular/angular-cli , Nativescript angular local file system images not showing #6343 on "/app/src/​images/intensepic.jpg" using ctrl+click its going to path of images and pick image but image is ghost removed the question label on Oct 4, 2018. I've tried all the possible means of loading images into a template.html in a rails/angular application but none of my methods are working. I imported my template file - import template from "./template.html"; Here's what my angular comp

Try this,

<img [src]="../../src/assets/images/1.jpg" alt="Ms dhoni" width="2000" height="2000"/>

Nativescript angular local file system images not showing · Issue , Build Your First Angular Website Courses - Lesson 7 of 18 ever decided to change that URL, then our app's logo would stop working. All we have to do is reference these images in our templates with a path that starts inside the src folder. For instance, if we have an image at src/assets/img/logo.png , we would add this  When I do ng serve to view my web application, the image does not display. What is the best practice to load up images in an Angular application? EDIT: See answer below. My actual image name was using spaces, which Angular did not like. When I removed the spaces in the file name, the image displayed correctly.

It should be

   <img src="assets/images/1.jpg" alt="Ms dhoni" width="200px" height="200px"/>

and make sure you have <base href="/"> in the index.html <head> tag

Adding an Image/Logo in Angular ―, If i'm keeping my image within src/images folder, its showing 404 file not you can .angular-cli.json In the screenshot you can see the path hierarchy for assets. Adding an Image/Logo in Angular. then our app's logo would stop working. All we have to do is reference these images in our templates with a path that starts

How to load image from src/images folder rather than from assets , Referencing images in relative paths. Help Request I am using visual studio for deployments with no problem. However when When I test locally some of the images are not rendering. I tried tweaking problem. in the angular-cli-json I have the following the folder will be found in our src folder with two typescript files. Hi ! Same issue here when trying to ng build --prod on my server. My path contains no special characters, my cases are respected. Working with. angular-cli : 6.2.3, Node : 8.9, Angular : 5.2.3

Referencing images in relative paths : Angular2, By default, Angular has an asset directory, located under the /src directory If you have some images, you can simply drop them in to this directory. the build directory by adding those files to the assets array inside angular.json . To achieve this, you can use the objects for assets configurations, instead  It simply is not possible for Angular to absolutely know where the files reside at runtime. Agreeing on Constraints If we decide on CommonJS formats AND we use a standard module loader, then we can use the variable which contains the absolute URL of the component class [when the module file is actually loaded]: the exact syntax is

Working With Assets and Global Styles and Scripts in Angular, Brought to you by: JavaScript SDK for Bold BI dashboard and analytics I fixed the problem by adding the folder path to the file angular.json. The path refers to the part of the URL that determines a unique view that should be displayed, and component refers to the Angular component that needs to be associated with a path. Based on a route definition that we provide (via a static RouterModule.forRoot(routes) method), the Router is able to navigate the user to a specific view.

  • Path should not contain src, src folder is the root of your app. http://localhost:4200/assets/images/1.jpg
  • @Ploppy,I have also tried using that but this is also not working
  • Did you solve this case?
  • i have simply using <img src> tag ,i am not doing any property binding .
  • Template parse errors: Parser Error: Unexpected token . at column 1 in [../../assets/images/1.jpg] in ng:///AppModule/HelloComponent.html@6:21 (" </ul> <img [ERROR ->][src]="../../assets/images/1.jpg" alt="Ms dhoni" width="2000" height="2000"/> <input "): ng:///AppModule/HelloComponent.html@6:21
  • try <img [src]="../../src/assets/images/1.jpg" alt="Ms dhoni" width="2000" height="2000">
  • try <img [src]="../../src/assets/images/1.jpg" alt="Ms dhoni" width="2000" height="2000">is this not the samething you have posted above
  • without the / tag
  • ,I have tried this,this is giving following error:"Failed to load resource: the server responded with a status of 404 (Not Found)"
  • localhost:4200/assets/images/1.jpg this error is coming ihave tried all this by seeing threads given regarding this same problem on stack overflow
  • Ok, one more thing, what is your baseUrl and have you <base href="/"> in index.html ?