pTutorial

New way to learn Programming

AngularJS function Example

Angular Directive Example

In this article we demonstrate, how to create function in AngularJS with the help of live example. As you know function play important role in any programming language.

As AngularJs is a library of JavaScript, so you can create simple java script function as well, they are working fine.

function Example

<html>
<head>
<title>Angular JS Controller with function Example</title>
<script src = "http://ajax.googleapis.com/ajax/libs
/angularjs/1.3.14/angular.min.js"></script>
</head>

<body>
<h2>AngularJS Sample Controller with 
function Application</h2>

<div ng-app = "ukApp" ng-controller = "ukController">
Enter first name: 
<input type = "text" ng-model = "name.FName"><br><br>
Enter last name: 
<input type = "text" ng-model = "name.LName"><br>
<br>
<button ng-click="fName()">Function call</button>
</div>

<script>
var mainApp = angular.module("ukApp", []);
mainApp.controller('ukController', function($scope) {
$scope.name = {
FName: "Umar",
LName: "Farooque",               
};           
$scope.fName = function() {
alert($scope.name.FName + " " + $scope.name.LName);
}
});
</script>

</body>
</html>


Download

See Also


QUOTES OF THE DAY

Beauty is truth, Truth beauty- That is all

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER