AngularJS Tutorial - Call functions in scope








The following code shows how to Call functions in scope.

Example


<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
<script type='text/javascript'>
function Controller($scope) {<!--from   ww w .j  av a2  s . c o m-->
    $scope.data = ["someText"];
    $scope.getIndex=function(){
        return "0";
    };
}
</script>
</head>
<body>
  <div ng-app ng-controller="Controller">
    <p ng-init="index=getIndex()"</p>
    <input ng-model="data[index]"/>
</div>
</body>
</html>

The code above is rendered as follows: