我的模态有一个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">×</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里面需要它。
我怎样才能做到这一点。提前致谢
答案 0 :(得分:2)
这种反直觉,但控制器的范围实际上是windowTemplate的父范围 所以你可以通过在windowTemplate中执行$ parent.modalTitle来访问modalTitle。