How to use Function in AngularJS Controllers ?
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