Monday 29 August 2016

How to use Function in AngularJS Controllers

Posted by : Manav Pandya

How to use Function in AngularJS



How to use Function in AngularJS Controllers ?


If you are new to AngularJS refer my Article : Understand Controller in AngularJS

Function in AngularJS :

  • In this article we will learn how to use Function in AngularJS

Following example shows its actual use :



<html>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body>
 
<div ng-app="Manav" ng-controller="Ctrl">
 
City: <input type="text" ng-model="city"><br><br><br>
Country: <input type="text" ng-model="country"><br><br><br>
Result: {{output()}}
 
</div>
 
<script>
var app = angular.module('Manav', []);
app.controller('Ctrl', function($scope) {
    $scope.city = "Rajkot";
    $scope.country = "India";
    $scope.output=function() {
 
 return $scope.city + " " + $scope.country;
}
});
</script>
 
</body>
</html>


Here we have used Function in AngularJS , which is named 'Manav' and inside that we have taken two text box value :


  • City
  • Country

Output :

Function in AngularJS




So try it with yourself and make appropriate changes .


basic asp.net mvc tutorials, Free asp.net mvc Tutorials for beginners, mvc, asp.net mvc, .net tutorials, mvc tutorial, mvc tutorials, asp.net mvc tutorials, mvc tutorial, mvc tutorials for Beginners , asp.net mvc Basics, basic mvc, mvc4, mvc5,.net mvc