Ng-Controller-3

 

In this example of Ng-Controller, We have two scope properties in the controller for firstname and lastname as: $scope.fName = "David"; $scope.lName = "Doe"; And a function which will join the firstname and lastname and return the full name as: $scope.flName = function () { return $scope.fName + " " + $scope.lName; } And html side: First Name:

Last Name:

Full Name: {{flName()|lowercase}}

 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome to LearnKode - A code learning platform</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> </head> <body ng-app="app"> <div ng-controller="controller"> <div class="container"> <br /> First Name: <input class="form-control" type="text" ng-model="fName"><br> Last Name: <input class="form-control" type="text" ng-model="lName"><br> Full Name: <b>{{flName()|lowercase}}</b> </div> </div> <script> var app = angular.module('app', []); app.controller('controller', function ($scope) { $scope.fName = "David"; $scope.lName = "Doe"; $scope.flName = function () { return $scope.fName + " " + $scope.lName; } }); </script> </body> </html>
Output