-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-communication-factory.html
More file actions
35 lines (35 loc) · 1.2 KB
/
angular-communication-factory.html
File metadata and controls
35 lines (35 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>angular-communication-factory</title>
<script type="text/javascript" src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body ng-app="app">
<div ng-controller="MainCtrl">
<input type="text" ng-model="test" />
<button ng-click="change()">click me</button>
</div>
<div ng-controller="sideCtrl">
{{name}}
<button ng-click="add()">change my name </button>
</div>
<script>
var app = angular.module('app', []);
app.factory('instance', function(){
return {};
});
app.controller('MainCtrl', function($scope, instance) {
$scope.change = function(){
instance.name = $scope.test;
console.log(instance);
};
});
app.controller('sideCtrl', function($scope, instance) {
$scope.add = function(){
$scope.name = instance.name;
};
});
</script>
</body>
</html>