gpt4 book ai didi

javascript - 以 Angular 访问窗口 TemplateUrl 内的范围

转载 作者:行者123 更新时间:2023-11-29 14:49:36 25 4
gpt4 key购买 nike

我的模式有一个 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>

我的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;
}]
});

但似乎无法从 modal.html 模板访问我的范围。但我可以从 create-job-modal.html 模板访问它。我在 modal.html 中需要它。

我怎样才能做到这一点。提前致谢

最佳答案

这有点违反直觉,但 Controller 的作用域实际上是 windowTemplate 的父作用域。
因此,您可以通过在 windowTemplate 中执行 $parent.modalTitle 来访问 modalTitle。

关于javascript - 以 Angular 访问窗口 TemplateUrl 内的范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27702427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com