Search code examples
javascriptangularjsangular-strap

Angular Strap Popover $scope.$parent unexpected behavior


In my application I'm generating two types of popover one static and another dynamic from a given situation.

My purpose is to update a scope variable of my parent controller, I usually do this like so:

$scope.$parent.myVariable = 'Hello Parent';

Nevertheless I'm not able to access my parent from the dynamic popover. I'm using a templated popover with angular strap and injecting it a controller.

This is my plunker example of What I want to do.

After digging a little in my popover controller $scope I discover that I'm able to get my parent (mainCtrl in the plunker example) like so:

 $scope.$parent.$parent.$parent.trackName ='Hello ' + $scope.name;

This is like a big inception but I found it :). Anyway I can't access it from the dynamic popover.

How can I get my parent from the popoverCtrl from both?


Solution

  • Here is one solution.

    your plunker modified

    1) add scope to your dynamic call to tie two scopes together.

    scope: $scope
    

    2) use object to bypass finding the correct $parent level

    $scope.my = {};
    $scope.my.name = "this is now available in all your popovers"