【发布时间】:2015-05-12 09:48:37
【问题描述】:
我正在使用Dan Wahlin's modal 服务并使其正常工作,但是如果我更改 modal.html 以在正文中包含部分模板,我不知道如何获取模型模态的“确定”点击结果中的模板数据。
here 和here 有两个类似的问题,但它们在模态表单中包含模型数据,而不是在单独的模板中。
我的想法是我可以有一个用于结果数据的模板控制器,但是我将如何从模态服务访问它并将其返回给调用控制器?
modal.html:
<div class="inmodal">
<div class="modal-header">
<h4 class="modal-title">{{modalOptions.headerText}}</h4>
</div>
<div class="modal-body">
<div ng-include="modalOptions.bodyTemplateUrl" ></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-white" data-ng-click="modalOptions.close()">{{modalOptions.closeButtonText}}</button>
<button class="btn btn-primary" data-ng-click="modalOptions.ok();">{{modalOptions.actionButtonText}}</button>
</div>
控制器:
var modalOptions = {
closeButtonText: 'Cancel',
actionButtonText: 'Save',
headerText: 'Modal Title',
bodyText: 'Nicy body.',
bodyTemplateUrl: 'modules/users/views/account/user-password.partial.html'
};
modalService.showModal({}, modalOptions).then(function (result) {
console.log(result.currentPassword);
if (result === 'ok') {
$scope.changeUserPassword();
}
});
用户密码.partial.html:
<div > <!-- PasswordController? -->
<form name="passwordForm" class=" form-horizontal" autocomplete="off">
<fieldset>
<div class="form-group">
<input type="password" id="currentPassword" name="currentPassword" class="form-control" data-ng-model="passwordDetails.currentPassword" placeholder="Current password">
</div>
<div class="form-group">
<input type="password" id="newPassword" name="newPassword" class="form-control" data-ng-model="passwordDetails.newPassword" placeholder="New password">
</div>
<div class="form-group">
<input type="password" id="verifyPassword" name="verifyPassword" class="form-control" data-ng-model="passwordDetails.verifyPassword" placeholder="Verify password">
</div>
</fieldset>
</form>
我没有创建 plunker,因为上面的链接显示了相同的代码,除了我包含的 bodyTemplateUrl。
【问题讨论】:
-
你能发布你的部分内容吗?
-
当然,我已经编辑了我的问题。
标签: javascript angularjs