0

In module named EventDetails I have two controllers attachedFilesList and EventDetailsctrl.

I need to pass string value from EventDetailsctrl controller to attachedFilesList controller.

How can I pass between controllers in same module?

2
  • 1
    see this stackoverflow.com/questions/11252780/… Commented Jun 26, 2016 at 7:24
  • Use events. ie: $emit from one controller. Then listen in the other controller. Commented Jun 26, 2016 at 7:24

2 Answers 2

3

Solution is attached below:

In EventDetailsctrl

$rootScope.$broadcast('pass-value', 'dummyVal');

In attachedFilesList

$scope.$on('pass-value', function(event, value) {
  // value is the object which is passed from $broadcast
});
Sign up to request clarification or add additional context in comments.

Comments

1

You can also pass the data from one controller to another controller using service.

EventDetails
  .controller('attachedFilesList', ['$rootScope', '$scope', 'myservice',
     function($rootScope, $scope, myservice) {
         $scope.myservice = myservice;
     }
  ]);

EventDetails
  .controller('EventDetailsctrl', ['$rootScope', '$scope', 'myservice',
     function($rootScope, $scope, myservice) {
         $scope.myservice = myservice;
     }
  ]);

EventDetails
   .service('myservice', function() {
       this.name = "value";
   });

Here is the Plnkr

Hope it helps :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.