AngularJS Tutorial - Call scope function in expression








The following code shows how to call scope function in expression.

Example


<!DOCTYPE html>
<html  ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
</head><!--  w  w  w .ja v  a2 s.  c o  m-->
<body>
<div ng-app="myApp" ng-controller="main">
    {{render(true)}}
    <br/>
    {{render(false)}}
</div>
<script type='text/javascript'>

angular.module("myApp", []);

function main($scope) {
    $scope.render = function(condition) {
        return condition ? "This is rendered when condition == TRUE" : "This is rendered when condition == FALSE";
    };
}
</script>
</body>
</html>

The code above is rendered as follows: