Skip to content

Instantly share code, notes, and snippets.

@anonymoussc
Created October 27, 2015 06:28
Creating Multiple Distinct Controllers
<!DOCTYPE html>
<html ng-app="exampleApp">
<head>
<title>Controllers</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
<script>
var app = angular.module("exampleApp", []);
app.controller("firstController", function($scope) {
$scope.dataValue = "Hello, Adam";
$scope.reverseText = function() {
$scope.dataValue = $scope.dataValue.split("").reverse().join("");
}
});
app.controller("secondController", function($scope) {
$scope.dataValue = "Hello, Jacqui";
$scope.changeCase = function() {
$scope.dataValue = $scope.dataValue.toUpperCase();
};
});
</script>
</head>
<body>
<div class="well" ng-controller="firstController">
<h4>First Controller</h4>
<div class="input-group">
<span class="input-group-btn">
<button class="btn btn-default" type="button" ng-click="reverseText()">Reverse</button>
</span>
<input class="form-control" ng-model="dataValue">
</div>
</div>
<div class="well" ng-controller="secondController">
<h4>Second Controller</h4>
<div class="input-group">
<span class="input-group-btn">
<button class="btn btn-default" type="button" ng-click="changeCase()">
Case
</button>
</span>
<input class="form-control" ng-model="dataValue">
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment