简体   繁体   中英

Angularjs ng-submit function is not working

I have a ng-template in my html view and there is a form inside the ng-template.So i need to submit form data through the form and i'm using ng-submit to do that.But when i click on submit button nothing happens.Other data binding works with text fields in the form using ng-model with my controller.Following is my html code.

   <script type="text/ng-template" id="updatetemplate">
   <div class="box box-primary">
   <div class="box-header with-border">
   <h3 class="box-title">Update</h3>
   </div>
   <!-- /.box-header -->
   <!-- form start -->
   <form name="update_form" ng-submit="updateUser(ngDialogData.id,  ngDialogData.currentname, ngDialogData.currentroleid)">
   <div class="box-body">
   <div class="form-group">
   <input type="hidden" name="userid" ng-model="ngDialogData.id"   class="form-control">
   <label>Name</label>
   <input type="text" class="form-control" name="name" ng-  model="ngDialogData.currentname" placeholder="Enter name">
   <p></p>
   <label>User role</label>
   <input type="text" class="form-control" name="roleid" ng-model="ngDialogData.currentroleid" placeholder="Enter name">
   </select>

   </div>

   </div>
   <!-- /.box-body -->

   <div class="box-footer">
     <button type="submit" class="btn btn-primary" name="updatebutton">Update</button>
   </div>
   </form>
   </div>
   <!-- /.box -->
   </script>

Some code correction need to be made :

  • remove blank space from ng- model .
  • instead of passing each ng-model into the updateUser function. just pass the whole ngDialogData object.
  • There is one invalid </select> tag in the form. remove that.

Working fiddle : https://jsfiddle.net/d8ye0sbz/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM