1

I am using angular bootstrap modal like this

   var myModal = $modal.open({
        controller: 'MyUpdateController as muc',
        templateUrl: 'views/create_form.html',

Now my parent controller is ParentController as PC.

I want to know how can I access PC inside muc or inside create_form template

0

1 Answer 1

1

You can always access controller alias from respective scope or its descendants carried down via inheritance (Alias is attached on the scope as a property name with the value holding the reference of controller instance). angular ui modal takes a scope property which you can use to set your modal to a specific scope (it is otherwise defaulted to rootScope). So set the scope property in your modal

 $modal.open({
    controller: 'MyUpdateController as muc',
    templateUrl: 'views/create_form.html',
    //Create a child scope of current scope or even pass the current $scope itself but be aware
    scope:$scope.$new() 

Inject $scope in your controller (MyUpdateController) and access parent scope as $scope.PC and you can access this alias in you template as well.

Another way you can probably use resolve property of the modal and pass the current parent scope to it.

$modal.open({
    controller: 'MyUpdateController as muc',
    templateUrl: 'views/create_form.html',
    resolve: {
       parentCtrl: function(){
         return ctrl; //return controller here
       }
    }

and inject parentCtrl as dependency in your MyUpdateController and get it and set it on the scope.

Sign up to request clarification or add additional context in comments.

7 Comments

thanks for that , but i didn't get return ctrl what will be ctrl here
@user3214546 It can just be your controller (whch i assume can access PC or it is PC). I just used a variable thats it, because you cannot pass this there, you would need to have it cached outside. So more like in your current controller you do var vm=this; inorder to avoid the this context access issue right (unless using typescript)?, ctrl is vm in that case.
so u mean , if i have vm = this then i can return vm . is that right
scope:scope or even scope:scope.$new() it should work, try it out
thanks , that worked , i had to use scope: $scope
|

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.