【问题标题】:Angular MaterialJS Dialog form with different save options具有不同保存选项的 Angular 材质对话框表单
【发布时间】:2019-03-23 18:14:42
【问题描述】:

我正在尝试在 mdDialog 中保存表单数据,但使用(保存并关闭)对话框和(保存)选项将保存表单数据,然后打开另一个对话框空对话框,而无需关闭并再次打开 mdDialog,问题是如何为两个保存操作以相同的形式调用相同的 SaveData 函数?

$scope.saveData = function (isValid) {
        if (isValid) {
          updateservice.postdata($scope.myformdata)
            .then(function (data) {
              $mdDialog.hide();
            });
      // error handling
        } 
      };

在模板中:

<md-dialog>
  <form name="form" ng-submit="saveData(form.$validform)" novalidate>
    <md-dialog-content>
      <div class="md-dialog-content">
        <div>
        </div>
        <table class="table display" border="1" span="1" name="newForm" novalidate role="form" ng-style="{ width: th.width }">
           </tr>
          <tr>
            <td><input type="text" class="form-control text-center" placeholder="required"  ng-required="true"></td>
            <td><input type="text" class="form-control text-center" placeholder="optional" ng-required="true"></td>
          </tr>
        </table>
      </div>
    </md-dialog-content>
    <md-dialog-actions layout="row">
      <md-progress-circular md-mode="indeterminate" md-diameter="20px" class="spinner"></md-progress-circular>
      <button type="button" class="btn btn-primary" ng-click="save()" >Save</button> 
      <button type="submit" class="btn btn-primar">Save and close</button> 
      <button type="button" class="btn btn-default" ng-click="cancel()" ng-disabled="loading">Cancel</button>
      </md-dialog-actions>
  </form>
</md-dialog>

我用类型按钮更改了保存按钮不发布表单数据,并且更改类型以提交,如保存和关闭保存数据,然后打开和关闭对话框。

这是带有我的代码的codePen:

https://codepen.io/anon/pen/ZqoYRx

【问题讨论】:

    标签: angularjs forms angularjs-material mddialog


    【解决方案1】:

    如何在保存函数中传递一个类似 isSaveAndClose 的参数:

    在 HTML 中:

    <button type="button" class="btn btn-primary" ng-click="save(false)" ng-show="!loading">Save</button> 
    <button type="button" class="btn btn-primar" ng-click="save(true)">Save and close</button>
    

    在 JS 中:

    $scope.save = function (isSaveAndClose) {
          saveData();
          if (isSaveAndClose)
            $mdDialog.hide().then(showCustomConfirm);
        };
    

    【讨论】:

    • 没有解决它, $mdDialog.show(confirm) 被调用,但对话框闪烁并立即关闭。 this.click = function click (isSaveAndClose) { save(); if (isSaveAndClose) { $mdDialog.show(confirm); } }; }], parent: parentE1, targetEvent: $event, controllerAs: 'saveAndclose', bindToController: true, }); $mdDialog.show(confirm) .then(function () { }, function () { }); }; save(): 调用后如何保持对话框打开?
    • 您的意思是如何在“保存”而不是“保存并关闭”之后保持对话框打开?如果要在“保存”后保持对话框打开,则只需在调用 saveData() 后清除模态数据。如果您想在选择“保存并关闭”后完全关闭模式,那么只需调用 $mdDiaglog.hide() 而不使用 .then(showCustomConfirm)。
    • 是的,这就是目标,调用 saveData() 后如何清除数据;
    • 如果你在模态中输入了模型,比如 vm.data/$scope.data,那么在 saveData() 之后调用 vm.data = null/$scope.data = null。用codePen试试吧……
    • 我已经改变了我的实现,我想对“保存”和“保存并添加”都使用一个 saveData 函数,如果之前调用 ShowNewDialog 是“保存并添加”,我该如何设置条件在更新服务中使用$mdDialog.hide(); 解决?那么我需要在模板中进行哪些更改以适应实施
    猜你喜欢
    • 1970-01-01
    • 2020-12-30
    • 1970-01-01
    • 2022-10-13
    • 1970-01-01
    • 2020-10-02
    • 1970-01-01
    • 1970-01-01
    • 2019-06-22
    相关资源
    最近更新 更多