Bind to function in scope in expression

Description

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

Example


<!doctype html>
<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js"></script>
</head><!--from w w w.ja  va 2 s  . c  o m-->
<body ng-app="myModule">
  <div ng-controller="MyCtrl">
    <input type="text" placeholder="Name" ng-model="name"/>
    <p>{{greeting()}}</p>
</div>
<script type='text/javascript'>
var myModule = angular.module('myModule', [])
    .controller('MyCtrl', ['$scope', function ($scope) {

        $scope.greeting = function(){
            return $scope.$eval('"Hello "+name');
        };
    }]);
</script>
</body>
</html>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Example »




Controller
Directives
Expression
Filter
Form
Inject
Scope
Server
Style
Template
Utilities