JavaScript Angularjs - communication between controller after unsubscribing from event listener on scope destroy angularjs communication between components,angularjs communication between controllers,angularjs communication

I am communicating from page2 controller to page1 controller in different views using $.emit and $on

     app.controller('mainController', ['$scope', function($scope) {
      $scope.message = "hello main page";
      $scope.$on('frompage2', function(event, data) {
        console.log("in parentController.........." + data);
      })
    }]);

    app.controller('page1Controller', ['$scope', '$rootScope', function($scope, $rootScope) {
      $scope.message = "hello page1";
      var msgFromPage2 = $rootScope.$on('frompage2', function(event, data) {
        console.log("in page1 controller" + data);

      })

      $scope.$on('$destroy', function() {
        msgFromPage2()
      });

    }]);

    app.controller('page2Controller', ['$scope',
      function($scope) {

        $scope.message = "Hello page 2"
        $scope.$emit('frompage2', 'this is from page2');

      }
    ]);

Its working fine if I don't use page1 controller scope destroy method to unsubscribe from event listening. What should be the correct approach to handle this situation so that I can subscribe to page2controller messages and still using destroy method in page1 controller scope to unsubscribe whenever page1 is getting unloaded

1]: http://plnkr.co/edit/dgitQBPRDjn9Z98kQ8Ad?p=preview

Answer:1

I am developing a small website for a school project. On one page I iterate over an array which is populated via SQL query. The data will be displayed like this: <ul class="list-group"> <...

I am developing a small website for a school project. On one page I iterate over an array which is populated via SQL query. The data will be displayed like this: <ul class="list-group"> <...

  1. value from element jquery
  2. element value from
  3. value element of art
  4. value element of art definition
  5. value element of design
  6. value element of art example
  7. value element of art photography
  8. value element in photography
  9. value element of art worksheet
  10. value element in html
  11. value of element javascript
  12. value of element n403 is incorrect
  13. value of element nm109 is incorrect
  14. value of element js
  15. value of element xpath
  16. element value in xml
  17. value of element 118
  18. value of element xslt
  19. value of element xsl
  20. element value in selenium

I'm building an hybrid app using ionic. Inside this app I decided to have Require.js as a dependency loader (maybe not the best choice but I'm used to work with that and since I have lots of projects ...

I'm building an hybrid app using ionic. Inside this app I decided to have Require.js as a dependency loader (maybe not the best choice but I'm used to work with that and since I have lots of projects ...

  1. warning tried to load angular twice

I have to restrict user to enter only numbers in a field in Angular2->form I have solution but backspace is not working in input field Can anybody have proper solution for that? form.html <...

I have to restrict user to enter only numbers in a field in Angular2->form I have solution but backspace is not working in input field Can anybody have proper solution for that? form.html <...

  1. restrict textbox input to numbers c#
  2. restrict textbox input to numbers
  3. restricting textbox input to numbers only in c#
  4. restricting textbox input to letters only
  5. restricting textbox input to numbers only
  6. restrict input in textbox javascript
  7. restricting input to textbox allowing only numbers
  8. wpf restrict textbox input length
  9. xaml restrict textbox input
  10. wpf restrict textbox input
  11. c# restrict textbox input
  12. restrict user input in textbox javascript
  13. restrict keyboard input to textbox javascript
  14. textbox restrict input

I know JQuery is a code smell in ReactJS because it traverses the entire DOM to do it's work. But, I've found some places where it's hard NOT to use it. This is one instance where I'd like to find a ...

I know JQuery is a code smell in ReactJS because it traverses the entire DOM to do it's work. But, I've found some places where it's hard NOT to use it. This is one instance where I'd like to find a ...