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
36
37
38
39
40
41
42
<!DOCTYPE html>
<html lang="ko" ng-app="test">
<head>
    <meta charset="utf-8">
</head>
<body>
   <div ng-controller="test1Controller" ng-bind="service"></div>
   <div ng-controller="test2Controller" ng-bind="service"></div>
   <script src="js/angular.min.js"></script>
   <script>
 
      //module       
      var app = angular.module('test', []);
 
      //service 데이터 공유        
      app.factory('service', function() {
         var shared = {};
         shared.a = 100;
         shared.b = '홍길동';
         return shared;
      });
 
      //controller        
      app.controller('test1Controller', function($scope, service) {
         service.a = 300000;
         $scope.service = service.a;
         console.log(service);
      });
 
      app.controller('test2Controller', function($scope, service) {
 
         $scope.service = service;
         console.log(service);
      });
 
      /*        
         test1Controller.$inject = ['$scope'];        
         test2Controller.$inject = ['$scope'];        
      */
   </script>
</body>
</html>



참고 : http://programmingsummaries.tistory.com/124

참고 : http://jeremyko.blogspot.kr/2014/12/angularjs-controller-broadcaston-or.html



반응형
Posted by 힘없는염소