When I use a variable in the view (HTML), when should I put it inside curly braces {{}}
?
I saw an example like this where an img
tag has two directives with the same value, but the first (ng-src
) variable should be in curly braces and the second (ng-show
) variable doesn't.
const myApp = angular.module('myApp', []);
myApp.controller('appController', ['$scope', $scope => {
$scope.img = 'https://img1.ak.crunchyroll.com/i/spire4/852ac41bdb5200059504e6e9ce6fc5ea1516289808_medium.png';
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myApp">
<div ng-controller="appController">
<img ng-src="{{img}}" ng-show="img">
</div>
</body>