AngularJS & Bootstrap modal form. Why data is sent for cancellation

I am facing an issue with AngularJS and Bootstrap UI on a modal form where when the form is canceled the view is triggered. Here is my Plunker to demonstrate my problem. On cancellation, I get an alert inside the view that shouldn't be there. What's wrong with this snippet?

Markup

     <div ng-controller="modalForm">
        <script type="text/ng-template" id="myModalContent.html">

                <div id="messages" class="well" ng-show="message">{{ message }}</div>
                <form name="addDomainForm" novalidate ng-submit="submit(addDomainForm)">
                <div class="modal-header">
                    <h6 class="modal-title"><i class="fa fa-plus"></i> add new Item </h6>
                </div>

                <div class="modal-body">

                        <div class="form-group">
                            <input type="domain" ng-model="formData.domain" class="form-control" id="domainAddress" placeholder="Domain Adresse">
                        </div>

                        <textarea rows="10" ng-model="formData.description" class="form-control" placeholder="Beschreiben Sie Ihre AktivitΓ€t" ng-minlength="15"></textarea>

                </div>

                <div class="modal-footer">
                    <input type="submit" class="btn btn-primary" value="Save" />
                    <button class="btn btn-warning" ng-click="cancel()">Cancel</button>
                </div>
                </form>


            </script>

            <button class="btn btn-success" ng-click="open()"><i class="glyphicon glyphicon glyphicon-plus-sign icon-plus-sign"></i> new Item </button>

</div>

      

Angular

angular.module("testModal", ['ui.bootstrap'])
.controller("modalForm", function($scope, $modal) {
  $scope.addDomainForm = {};

  $scope.open = function (size) {
    var modalInstance = $modal.open({
      templateUrl: 'myModalContent.html',
      controller: ModalInstanceCtrl,
      size: size
    });

  };

}); 

var ModalInstanceCtrl = function ($scope, $modalInstance,$log) {

  $scope.cancel = function () {
    $modalInstance.dismiss('cancel');
  };

  $scope.submit = function(addDomainForm) {
   alert();
  };

};

      

+3


source to share


1 answer


Adding the type attribute; type="button"

for the button works for me:

Example



 <button type="button" class="btn btn-warning" ng-click="authModel.cancel()">Cancel</button>`

      

+4


source







All Articles