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
반응형
'AngularJS' 카테고리의 다른 글
[AngularJS] 동적요소삽입 ng-bind-html (0) | 2017.03.28 |
---|---|
[AngularJS] 앵귤러js 컨트롤러간 데이터 공유 (0) | 2016.12.26 |
[AngularJS] ng-repeat 리스트 반복문 출력 - 추가, 삭제 (0) | 2016.12.12 |