Varun_Krishna

$save().then()

Jan 21st, 2014
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. Template file(.html)
  2. <html ng-app=""><head>
  3. <title></title></head>
  4. <body>
  5. ....
  6. ....
  7. ....
  8. ...
  9. <button class= "btn btn-primary" ng-click = "saveUpdate()">
  10. </body>
  11. </html>
  12. <!-- ==========X ============= -->
  13. js file's content
  14.  
  15. angular.module('modal-controller', ['ui.bootstrap.modal'])
  16.  
  17. .factory('ModalController', ['$modal', function($modal) {
  18.  
  19. var service = {
  20.  
  21. model: undefined,
  22. original: undefined,
  23.  
  24. saveButtonTitle: undefined,
  25. revertButtonTitle: undefined,
  26.  
  27. modalInstance: undefined,
  28.  
  29. init: function(model, createMode, $modalInstance) {
  30. service.model = model;
  31. service.original = angular.copy(service.model);
  32.  
  33. service.saveButtonTitle = createMode ? 'Create' : 'Save';
  34. service.revertButtonTitle = createMode ? 'Clear' : 'Revert';
  35.  
  36. service.modalInstance = $modalInstance;
  37. return this;
  38. },
  39.  
  40. saveUpdate: function () {
  41. service.model.$save().then(function() {
  42. service.modalInstance.close(service.model);
  43. });
  44. },
  45.  
  46. cancel: function () {
  47. service.modalInstance.dismiss('cancel');
  48. },
  49.  
  50. But when clicking on the save button in the template the action is taking place.
Advertisement
Add Comment
Please, Sign In to add comment