Skip to content

Instantly share code, notes, and snippets.

@terrancebryant
Created May 6, 2014 21:44
Show Gist options
  • Select an option

  • Save terrancebryant/19ef51e2ca7f04e17d29 to your computer and use it in GitHub Desktop.

Select an option

Save terrancebryant/19ef51e2ca7f04e17d29 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Controller" />
<script src="http://code.jquery.com/jquery.min.js"></script>
<link href="http://getbootstrap.com/dist/css/bootstrap.css" rel="stylesheet" type="text/css" />
<script src="http://getbootstrap.com/dist/js/bootstrap.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div ng-app="myApp">
<div ng-controller="FirstCtrl">
<input type="text" class="form-control" ng-model="data.message">
<h3>{{data.message}}</h3>
</div>
<div ng-controller="SecondCtrl">
<input type="text" class="form-control" ng-model="data.message">
<h3>{{ reversedMessage(data.message) }}</h3>
</div>
</div>
</body>
</html>
var myApp = angular.module('myApp', []);
myApp.factory('Data', function () {
return { message: "I'm data from a service" };
});
function FirstCtrl($scope, Data) {
$scope.data = Data;
}
function SecondCtrl($scope, Data) {
$scope.data = Data;
$scope.reversedMessage = function(message) {
return message.split("").reverse().join("").toUpperCase();
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment