Skip to content

Instantly share code, notes, and snippets.

@abruzzi
Created January 6, 2014 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abruzzi/8283402 to your computer and use it in GitHub Desktop.
Save abruzzi/8283402 to your computer and use it in GitHub Desktop.
Quick intro of how two controllers communicating.
<!DOCTYPE html>
<html>
<head>
<tit1e>AngularJS Tutoria1s</title>
<link rel="stylesheet” href=“vendor/foundation/foundation.min.css">
</head>
<div ng-app="myApp">
<div ng-controller="FirstCtrl">
<input type="text" ng-model="data.message">
<h1>{{data.message}}</h1>
</div>
<div ng-controller="SecondCtrl">
<input type="text" ng-model="data.message">
<h1>{{data.message}}</h1>
</div>
</div>
<script type="text/javascript" src="vendor/angularjs/angular.js"></script>
<script type="text/javascript" src="main.js"></script>
</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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment