AngularJS Tutorial - ng-src with image element








The following code shows how to use ng-src with image element.

Example


<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
<script type='text/javascript'>
var myApp = angular.module('myApp', []);
<!--from   www . j a v  a2s  .c  o  m-->
myApp.controller('myCtrl',
    function ($scope) {
        $scope.url = 'www.java2s.com/style/download.png';
    }
);
</script>
</head>
<body>
  <div ng-app="myApp">
    <div ng-controller="myCtrl">
        <img src="http://{{url}}"/>
        <img ng-src="http://{{url}}"/>
    </div>
</div>
</body>
</html>

The code above is rendered as follows: