FreeKB - How to create images in Angular JS
How to create images in Angular JS

Home > Search > How-to

In this example, The Angular controller will pass an image from the Controller to the View.



The following Controller contains a variable named profile which contains the path to an image. 

var myApp = angular
	.module("myModule", [])
	.controller("myController", function ($scope) {
	var profile = {
		picture: "images/john_doe.png"		
	$scope.myVariable = profile ;



In the view, the following markup can be used to get the picture from the profile variable. The ng-src directive is used to get the image.

    <script src="js/angular.min.js"></script>
    <script src="js/myAngular.js"></script>
<body ng-app="myModule">
    <div ng-controller="myController">
      <img ng-src="{{ myVariable.picture }}">


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter 125ed in the box below so that we can be sure you are a human.