Skip to content

Instantly share code, notes, and snippets.

@bakkiraju
Created March 22, 2017 02:31
Show Gist options
  • Save bakkiraju/638c78907e54b37c3b6330cde57ce64a to your computer and use it in GitHub Desktop.
Save bakkiraju/638c78907e54b37c3b6330cde57ce64a to your computer and use it in GitHub Desktop.
MultiController-AngularJS example
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp">
<div ng-controller="personCtrl">
First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>
<br>
Full Name: {{fullName()}}
</div>
<br>
<br>
<div ng-controller="otherCtrl">
First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>
<br>
Full Name: {{fullName()}}
</div>
<br>
<br>
<div ng-controller="anotherCtrl">
First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>
<br>
Full Name: {{fullName()}}
</div>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('personCtrl', function($scope) {
$scope.firstName = "John";
$scope.lastName = "Doe";
$scope.fullName = function() {
return $scope.firstName + " " + $scope.lastName;
};
});
app.controller('otherCtrl', function($scope) {
$scope.firstName = "James";
$scope.lastName = "smith";
$scope.fullName = function() {
return $scope.firstName + " " + $scope.lastName;
};
});
app.controller('anotherCtrl', function($scope) {
$scope.firstName = "Bilahari";
$scope.lastName = "Akkiraju";
$scope.fullName = function() {
return $scope.lastName + " " + $scope.firstName;
};
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment