简体   繁体   English

以角度为单位访问windowTemplateUrl中的范围

[英]access scope inside windowTemplateUrl in angular

I have a windowTemplateUrl for my modal as follow 我有一个windowTemplateUrl我的模态如下

<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 is as follow 我的js代码如下

$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 that my scope is not accessible from modal.html template. 但似乎无法从modal.html模板访问我的范围。 But i can access it from create-job-modal.html template. 但我可以从create-job-modal.html模板访问它。 I need it inside modal.html. 我在modal.html里面需要它。

How can i achieve this. 我怎样才能做到这一点。 Thanks in advance 提前致谢

It is kind of counter-intuitive but the scope of the controller is actually the parent scope of the windowTemplate. 它有点反直觉,但控制器的范围实际上是windowTemplate的父范围。
So you can access modalTitle by doing $parent.modalTitle in your windowTemplate. 因此,您可以通过在windowTemplate中执行$ parent.modalTitle来访问modalTitle。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM