我正在使用角带,特别是它的模态,我在编码时使用this样式。它是我控制器的一部分:
function parentController($scope, $routeParams, $location, $modal) {
var vm = this;
vm.message = '';
...
模态的html部分:
<div class="modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" ng-show="title">
<button type="button" role="button" class="close" aria-label="Close" ng-click="$hide()"><span aria-hidden="true">×</span></button>
<h1 class="modal-title" ng-bind="title"></h1>
</div>
<div class="modal-body" ng-bind-html="content">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success pull-left" ng-click="$hide();parentController.f1();" aria-label="Close">yes</button>
<button type="button" class="btn btn-danger pull-left" ng-click="$hide();parentController.f2();" aria-label="Close">no</button>
</div>
</div>
</div>
</div>
这是我在控制器中的模态定义:
var modalObject = {
scope: $scope,
templateUrl: 'path/to/modal.html',
title: 'desc',
content: '<p>enter description here</p> <textarea ng-model="parentController.message" class="form-control" rows="10"></textarea>',
show: false
};
$modal(modalObject);
现在,我将访问parentController中的消息值。当我在f2函数中记录vm.message
时,它是空的。访问它的解决方案是什么?
答案 0 :(得分:0)
我最终通过从控制器中删除内容并将其手动添加到html代码来解决问题。
var modalObject = {
scope: $scope,
templateUrl: 'path/to/modal.html',
title: 'desc',
show: false
};
$modal(modalObject);
模态的html代码:
<div class="modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" ng-show="title">
<button type="button" role="button" class="close" aria-label="Close" ng-click="$hide()"><span aria-hidden="true">×</span></button>
<h1 class="modal-title" ng-bind="title"></h1>
</div>
<div class="modal-body">
<p>enter description here</p>
<textarea ng-model="parentController.message" class="form-control" rows="10"></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success pull-left" ng-click="$hide();parentController.f1();" aria-label="Close">yes</button>
<button type="button" class="btn btn-danger pull-left" ng-click="$hide();parentController.f2();" aria-label="Close">no</button>
</div>
</div>
</div>
</div>
所以,我的模型中有textarea的值