0

I have 2 views,each one has a controller,I want to send data from View1 to View2 when I click on the "BL" Button:

this is View1: enter image description here

and this is View2: enter image description here

I tried to use the events my try,but the Controller2 will be activated only when I click on the "BL" Button I thought to use a service to send Data from controller1 to controller2,but I think it's not my case so please is there any help,how can I send data from View1 to View2 thanks

Edit: this is my second try:

View1/controller1:

 $scope.BLButton = function(){


    $scope.foo = Service.foo;
    Service.foo = '85';

    }
    .factory('Service', function() {
                                  var Service = {
                                        foo: '85'
                                      };
                                      return Service;
                                    });

View2/Controller2:

//this method is called to display the data in the input Text from a web Service
$scope.parentmethod = function() {
  //traitement
$scope.foo = Service.foo;
....
}

the problem with my code is that the method "parentmethod" of Controleller2 is never called when I click on the "BL" button

Community
  • 1
  • 1
user3821206
  • 609
  • 1
  • 9
  • 22

1 Answers1

1

The best approach is to move all you business logic (BL) to a service which will maintain app state. You're trying to misuse controllers in a way, because their only goal is to glue presentation and BL and not to hold app state in any form. The problem is that controllers are created and destroyed on view change, so they don't fit as state holders. In your case you can store data in a service (which is instantiated and alive all the time your app works) and then retrieve it in another view in controller.

Ilya_S
  • 184
  • 2