AngularJS Tutorial - Bind image URL to value in scope








The following code shows how to Bind image URL to value in scope.

Example


<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
</head><!--from  w  w w  . j  ava 2  s . com-->
<body>
  <div ng-app ng-controller="x">
    <img src="{{src}}" />
</div>
<script type='text/javascript'>
function x($scope) {
    $scope.src = 'http://www.java2s.com/style/download.png';
}
</script>
</body>
</html>

The code above is rendered as follows: