Guest User

Untitled

a guest
Jan 17th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. <div ng-controller="ParentCtrl as parent">
  2. <div ng-controller="ChildOneCtrl as chi1"></div>
  3. <div ng-controller="ChildTwoCtrl as chi2"></div>
  4. <div ng-controller="ChildThreeCtrl as chi3"></div>
  5. </div>
  6.  
  7. function ChildOneCtrl ($scope, sharedService) {
  8.  
  9. var chi1 = this;
  10.  
  11. sharedService.getChildOneData()
  12. .then(function (res) {
  13. $rootScope.$emit('childOneDataEmited', res.data);
  14. }).catch(function (err) {
  15. console.log(err);
  16. });
  17. }
  18.  
  19. function ChildTwoCtrl ($scope, $rootScope, sharedService) {
  20.  
  21. var chi2 = this;
  22.  
  23. var onEmitChildOne = $rootScope.$on('childOneDataEmited', function (event, data) {
  24. getData(data);
  25. });
  26.  
  27. $scope.$on('$destroy', onEmitChildOne);
  28.  
  29. function getData(data){
  30.  
  31. var chi1Data = data;
  32.  
  33. if(chi1Data.uEnabled){
  34. sharedService.getChildTwoData()
  35. .then(function (res) {
  36. $rootScope.$emit('childTwoDataEmited', res.data);
  37. }).catch(function (err) {
  38. console.log(err);
  39. });
  40. }
  41. }
  42. }
  43.  
  44. function ChildThreeCtrl ($scope, $rootScope, sharedService) {
  45.  
  46. var chi3 = this;
  47.  
  48. var onEmitChildThree = $rootScope.$on('childTwoDataEmited', function (event, data) {
  49. getData(data);
  50. });
  51.  
  52. $scope.$on('$destroy', onEmitChildThree);
  53.  
  54. function getData(data){
  55.  
  56. var chi2Data = data;
  57.  
  58. sharedService.getChildThreeData()
  59. .then(function (res) {
  60. //to do some data manipulation
  61. console.log(res)
  62. console.log(chi2Data)
  63. }).catch(function (err) {
  64. console.log(err);
  65. });
  66. }
  67. }
Add Comment
Please, Sign In to add comment