0

This is the situation: I've controller2 nested inside controller1. I want to pass or bind some data from the view into controller 2 and show this data in a modal. The modal opens but doesn't show the data passed from the view. The console however shows the data is passed into the controller.

As you can see I'm using Angularjs with bootstrap 4 and jQuery. I did several modals in only 1 controller at a time, but now I want to use this nested controller. How do I get the data into this particular modal?

VIEW:

<div ng-controller="controller1 as ctrl1">
....some code...
  <div ng-controller="controller2 as ctrl2">
    <h5 data-toggle="modal" data-target="#myModal" data-myparam="wood">
    open modal</h5>
  </div>
... some more code ...
</div>

<!-- MODAL -->
<div ng-controller="controller2 as ctrl2">
  <div class="modal fade" id="myModal" role="dialog">
   <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
     <h5>My parameter: {{ctrl2.param}}</h5>
    </div>
   </div>
  </div
</div>

MODEL for controller2:

....
$('#myModal').on('show.bs.modal', function(e){
  vm.param = e.relatedTarget.dataset.myparam;
  console.log(vm.param);
});
2
  • you can use $parent check this answer stackoverflow.com/questions/27097740/…, but i would strongly recommend to use a directive for second controller and bind it Commented Feb 4, 2018 at 11:20
  • @Panos K: The data doesn’t reside in the first controller. It’s only used in the second one. So I don’t think I can use $parent. I only want this data to show up in the modal. The console shows me the correct data. Why isn’t it showing up in myModal? Commented Feb 4, 2018 at 14:39

0

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.