sweetalert isConfirm with angularjs

sweetalert isConfirm with angularjs

我有一个示例 code here,我想在其中使用 isConfirm 和 sweet alert as 继续或添加新值。

 swal({
      title: "Are you sure?",
      text: "Save the name",
      type: "warning",
      showCancelButton: true,
      confirmButtonColor: "#DD6B55",
      confirmButtonText: "Save and Add Another",
      cancelButtonText: "New",
      closeOnConfirm: true,
      closeOnCancel: true
    }, function(isConfirm) {
      if (isConfirm) {
        // saves the input values & selected values using ajax call
        $scope.test = '';
      } else {
       // reset input values & selected values and fresh input again
        $scope.test = '';
        $scope.mysel = '-1';
      }
    });

但是在点击保存并添加另一个按钮后,模型值并没有在第一次清除。此外,它不会在单击 New 时重置。代码有什么问题?

你必须使用$scope.$apply();,否则它不会反映$scope变量中的值。

DEMO

您可以查看 here 有关 $scope.apply() 的更多信息。

希望对您有所帮助!