Accessible scope inside windowTemplateUrl in angular

I have a windowTemplateUrl for my modal as follows

<div tabindex="-1" role="dialog" class="modal fade" ng-class="{in: animate}" ng-style="{'z-index': 1050 + index*10, display: 'block'}" data-ng-click="close($event)">
    <div class="modal-dialog" ng-class="{'modal-sm': size == 'sm', 'modal-lg': size == 'lg'}">
        <div class="modal-content square-btn">
            <div class="modal-header custom-modal-header square-btn">
                <button type="button" class="close" data-dismiss="modal" ng-click="cancel($event)">
                    <span aria-hidden="true">&times;</span>
                    <span class="sr-only">Close</span>
                </button>
                <h3 class="modal-title">{{modalTitle}}--</h3>
            </div>
            <div class="modal-body" modal-transclude>

            </div>            
        </div>
    </div>
</div>

      

And my js code looks like this

$modal.open({
            windowTemplateUrl: 'templates/common/modal.html',            
            templateUrl: 'templates/jobs/create-job-modal.html',
            resolve: {
                modalTitle: function(){
                    return 'Create new position';
                }
            },
            controller: ['$scope', 'modalTitle', function( $scope, modalTitle ) {
                $scope.modalTitle = modalTitle;
            }]
        });

      

But it seems to me that my area is not accessible from the template modal.html

. But I can access it from the template create-job-modal.html

. I need this inside modal.html.

How can I achieve this. thanks in advance

+3


source to share


1 answer


It's kind of counter-intuitive, but the controller scope is actually the parent scope of the windowTemplate.
Thus, you can access modalTitle by doing $ parent.modalTitle in your windowTemplate.



+2


source







All Articles