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
- ModuleNotFounEerror:No module named celery in Django Project
- How to get domain name information from a Domain using Python
- ModulenotFoundError: no module named 'debug_toolbar' -SOLUTION
- How to create superuser in django project hosted in cPanel without terminal
- CSS & images not loading in django admin | cpanel without terminal
- Could not build wheels for mysqlclient, which is required to install pyproject.toml-based projects
- How to sell domain name on Godaddy (2023)
- TemplateSyntaxError at / Could not parse the remainder: ' + 1' from 'forloop.counter0 + 1'
Related Article