In large applications, it is common to store the controller in an external file.
<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<meta http-equiv= "x-ua-compatible" content= "Ie=edge"/>
<meta name= "viewport" content= "width=device-width,initial-scale=1"/>
<!--[If Lt IE 9]>
<script src= "Http://apps.bdimg.com/libs/html5shiv/3.7/html5shiv.min.js" ></script>
<script src= "Http://apps.bdimg.com/libs/respond.js/1.4.2/respond.js" ></script>
<! [endif]-->
<title></title>
<meta charset= "Utf-8"/>
<link rel= "stylesheet" href= "Bootstrap-3.3.5/dist/css/bootstrap.min.css"/>
<body>
<div class= "Container" >
<div data-ng-app= "Personapp" data-ng-controller= "Personctrl" >
Name: <input type= "text" data-ng-model= "FirstName"/>
Surname: <input type= "text" data-ng-model= "LastName"/>
<br/><br/>
The name is: {{fullName ()}}
</div>
</div>
<script src= "Jquery/jquery-2.1.4.js" ></script>
<script src= "Bootstrap-3.3.5/dist/js/bootstrap.min.js" ></script>
<script src= "Http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js" ></script>
<script src= "Js/presonctrl.js" ></script>
</body>
The code in Js/presonctrl.js is as follows:
Angular.module ("Personapp", []). Controller ("Personctrl", function ($scope) {$scope. FirstName = "W"; $scope. LastName = " WH "; $scope. FullName = function () {return $scope. firstname+ "" + $scope. LastName}})
AngularJS controllers in external files