Created
September 2, 2012 05:58
-
-
Save pmanijak/3595195 to your computer and use it in GitHub Desktop.
Service and template example with AngularJS for sharing data between controllers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html ng-app="project"> | |
<head> | |
<title>Angular: Service and template example</title> | |
<script src="http://code.angularjs.org/angular-1.0.1.js"></script> | |
<script src="script.js"></script> | |
</head> | |
<body> | |
<div ng-view></div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var projectModule = angular.module('project',[]); | |
projectModule.config(function($routeProvider) { | |
$routeProvider. | |
when('/', {controller:FirstCtrl, templateUrl:'x1.html'}). | |
when('/2', {controller:SecondCtrl, templateUrl:'x2.html'}); | |
}); | |
projectModule.factory('theService', function() { | |
return { | |
thing : { | |
x : 100 | |
} | |
}; | |
}); | |
function FirstCtrl($scope, $location, theService) { | |
$scope.thing = theService.thing; | |
$scope.name = "First Controller"; | |
} | |
function SecondCtrl($scope, theService) { | |
$scope.someThing = theService.thing; | |
$scope.name = "Second Controller!"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
<h2>{{name}}</h2> | |
<input ng-model="thing.x"/> | |
<a href="#2">next</a> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
<h2>{{name}}</h2> | |
<input ng-model="someThing.x"/> | |
<a href="#">back</a> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment