communication between controllers in angularjs -


the 1st controller has id. 2nd controller has function takes id , opens modal.

i want pass id 1st controller 2nd controller , open 2nd controller's modal while staying in 1st controller. there no relationship between these controllers.

i tried use $rootscope.broadcast things not working expected.

how can achieve feature ?

edit:

1st controller:

$scope.getid = function(id){         $scope.id = id;         $rootscope.$broadcast("info", $scope.id);     }  

2nd controller:

    $scope.viewmodal = function(id) {         $scope.id = id;         var modalinstance = $modal.open( {             templateurl: 'src/web/viewmodal.html',             controller: 'viewctrl',             size: 'lg',             resolve: {                 id: function () {                     return $scope.id;                 }             }        } );    }     $rootscope.$on("info", function(event, id) {         $scope.id = id;         $scope.viewmodal(id);     }); 

i not sure how modal 2nd controller gets invoked while clicking on $scope.getid 1st controller. kind of apprehensive use services @ stage because involve lot of code change existing setup.please advise.

communicating between controllers should done through service.

for modal part either figure out own logic or use ui-boostrap modal. supports throwing data @ have async request populating in modal based on id sent it. done giving modal own scope , each modal have resolve can use make sure modal has correct data in scope.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -