I am trying to call a external js file to implement angular js controller. Please find the code below. But it is not giving the result for the external js file access code is being added. Could someone correct me what am i doing mistake here?
[It gives the proper result if I don't have added the external js access code]
<!DOCTYPE html>
<html >
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"> </script>
<body ng-app="myApp">
<!-- Angular JS controller sample -->
<div ng-controller="myAppCtrl">
First name : <input type="text" ng-model="firstName"> <br>
Last name : <input type="text" ng-model="lastName"> <br>
Full name is : {{firstName + " " + lastName}} <br>
</div>
<script>
var app = angular.module('myApp',[]);
app.controller('myAppCtrl', function($scope) {
$scope.firstName = "Prabakar"
$scope.lastName = "Prabu"
});
</script>
<!-- Method based controller -->
<div ng-controller="methodCtrler">
<br>
First name is : <input type="text" ng-model="fName"> <br>
Last name is : <input type="text" ng-model="lName"> <br>
Full name : {{myFunction() }}
<br>
</div>
<script>
//var app1 = angular.module('myApp',[]);
app.controller ('methodCtrler', function($scope) {
$scope.fName = "Jonathan"
$scope.lName = "Gladwin"
$scope.myFunction = function() {
return $scope.fName + " " + $scope.lName;
}
});
</script>
<!-- Method call from external JS files -->
<br>
<div ng-controller ="ryanContrler">
My first name : <input type="text" ng-model="ryanFirstname"> <br>
My last name : <input type="text" ng-model="austinLastname"> <br>
My full name : {{fullName()}
</div>
<script src ="ryanNameContorller.js"></script>
</body>
</html>
ryanNameContorller.js
angular.module ('myApp', []).controller('ryanContrler', function($scope) {
$scope.ryanFirstname = "Ryan",
$scope.austinLastname = "Austin",
$scope.fullName = function () {
return $scope.ryanFirstname + " " + $scope.austinLastname;
}
});
And the result is,
