第一类提问者,长期阅读者。Angular 的新手。
我正在尝试创建一个用于扩展文本框的弹出模式。(如果您曾经处理过 Access,请考虑 shift F2)。所以,我有一个带有多个文本框的表单,它利用 ng-model 进行双向绑定。我想用 a 打开一个模式,<textarea>
这样用户就可以输入(并查看)比简单文本框更多的内容。
目前,绑定到每个字段的数据将正确打开到弹出窗口的文本区域(将数据传递给模式)。但是,如何将数据恢复为原始表单并输入正确的字段?
mainForm.cshtml
<div class="col-md-4">
<button type="button" ng-click="openTextEditor(vm.firstName)">First Name</button>
<input class="form-control" type="text" name="firstName" ng-class="{'edited':vm.firstName}" ng-model="vm.firstName">
</div>
<div class="col-md-4">
<button type="button" ng-click="openTextEditor(vm.middleName)">Middle Name</button>
<input class="form-control" type="text" name="middleName" ng-class="{'edited':vm.middleName}" ng-model="vm.middleName">
</div>
<div class="col-md-4">
<button type="button" ng-click="openTextEditor(vm.lastName)">Last Name</button>
<input class="form-control" type="text" name="lastName" ng-class="{'edited':vm.lastName}" ng-model="vm.lastName">
</div>
mainForm.js
$scope.openTextEditor = function(textValue) {
$uibModal.open({
templateUrl: '~/textEditorModal.cshtml',
controller: 'textEditorModal as vm',
backdrop: 'static',
resolve: {
textValue: function() {
return textValue;
}
}
});
};
textEditorModal.cshtml
<div>
<div class="modal-header">
<h4 class="modal-title">
</h4>
</div>
<div class="modal-body">
<div busy-if="vm.loading">
<form name="textEditor">
<div class="input-group margin-bottom-10">
<textarea id="textBox" type="text" class="form-control" cols="25" rows="7" placeholder="Type text here...." ng-model="vm.textValue" enter-key="vm.saveModal()"></textarea>
</div>
</form>
</div>
</div>
<div class="modal-footer">
<button type="button" ng-disabled="vm.saving" class="btn btn-default" ng-click="vm.cancelModal()">Cancel</button>
<button type="submit" button-busy="vm.saving" class="btn btn-primary blue" ng-click="vm.saveModal()" ng-disabled="textEditor.$invalid"><i class="fa fa-save"></i> <span>Save</span></button>
</div>
</div>
textEditorModal.js
appModule.controller('common.views.common.textEditorModal', [
'$scope', '$uibModalInstance', 'textValue',
function($scope, $uibModalInstance, textValue) {
var vm = this;
vm.loading = false;
vm.textValue = textValue;
vm.cancelModal = function() {
$uibModalInstance.dismiss();
};
vm.saveModal = function() {
vm.saving = true;
$uibModalInstance.close(vm.textValue);
};
}
]);
提前谢谢了!