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 add two numbers in Android Studio? | Source Code
- FindViewByID returns null in android studio -SOLVED
- Saving changes is not permitted in SQL SERVER - [SOLVED]
- Restore of database failed. File cannot be restored over the existing. -[SOLVED]
- One or more projects in the solution were not loaded correctly in Visual Studio 2019 | FIXED
- How to find Laptop's Battery Health?
- SOLVED-Related Field got invalid lookup: icontains error in Django
- How to enable Search Feature in Django admin?
Related Article