Skip to content

Instantly share code, notes, and snippets.

@magnet88jp
Created May 11, 2015 14:29
Show Gist options
  • Select an option

  • Save magnet88jp/2314db33ea8146d17b19 to your computer and use it in GitHub Desktop.

Select an option

Save magnet88jp/2314db33ea8146d17b19 to your computer and use it in GitHub Desktop.
AngularJS Factory Test1
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular.min.js"></script>
<script>
var testApp = angular.module('app', []);
testApp.factory('TestFact1', function () {
return {
"elem1" : "a",
"elem2" : "b"
}
});
testApp.controller('TestCtrl1', ['$scope', 'TestFact1', function ($scope, TestFact1) {
$scope.test1 = TestFact1;
$scope.setD = function() {
TestFact1.elem1 = "d";
}
}]);
testApp.controller('TestCtrl2', ['$scope', 'TestFact1', function ($scope, TestFact1) {
$scope.test2 = TestFact1;
$scope.setC = function() {
TestFact1.elem2 = "c";
}
}]);
</script>
</head>
<body ng-app="app">
<h1>Factoryテスト</h1>
<div ng-controller="TestCtrl1">
<h2>TestView1</h2>
<p>{{test1.elem1}}</p>
<p>{{test1.elem2}}</p>
<button ng-click="setD()">setD</button>
</div>
<div ng-controller="TestCtrl2">
<h2>TestView2</h2>
<p>{{test2.elem1}}</p>
<p>{{test2.elem2}}</p>
<button ng-click="setC()">setC</button>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment