In this article, I will show you how to display image in angularjs ng src. In html document you should display an image using <img> tag element using the src attribute. In Angular use ng-src attribute to bind the image.
The Angular markup {{mc.ImageUrl}} in a src does not work right. The browser will fetch from the URL with the literal text Until the AngularJs expression replaces inside the {{mc.ImageUrl}}. The angular ng-src resolves this problem.
HTML Code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
<script type="text/javascript">
(function () {
'usestrict';
angular
.module('app', [])
.controller('myController',myController);
function myController() {
var mc = this;
mc.ImageUrl = "http://www.google.com/logos/doodles/2016/first-day-of-school-2016-5187470943584256-hp.jpg";
}
})();
</script>
</head>
<body ng-app="app">
<h2>Display image in AngularJS using ng-src directive</h2>
<div ng-controller="myControlleras mc">
<img alt="" ng-src="{{mc.ImageUrl}}" />
</div>
</body>
</html>
Post your comments / questions
Recent Article
- How to create custom 404 error page in Django?
- Requested setting INSTALLED_APPS, but settings are not configured. You must either define..
- ValueError:All arrays must be of the same length - Python
- Check hostname requires server hostname - SOLVED
- How to restrict access to the page Access only for logged user in Django
- Migration admin.0001_initial is applied before its dependency admin.0001_initial on database default
- Add or change a related_name argument to the definition for 'auth.User.groups' or 'DriverUser.groups'. -Django ERROR
- Addition of two numbers in django python
Related Article