Advertisement
Guest User

Untitled

a guest
May 24th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. app.config(['$mdDialogProvider', function($mdDialogProvider){
  2. console.log($mdDialogProvider);
  3. // ^ $get/addMethod/addPreset/setDefaults
  4.  
  5. var defaults = {
  6. options: function(){
  7. return {
  8. hasBackdrop: false
  9. }
  10. }
  11. }
  12. $mdDialogProvider.setDefaults(defaults);
  13. }]);
  14.  
  15. $provide.decorator(name, decorator);
  16.  
  17. .config(function ($provide) {
  18. // Decorate the $mdDialog service using $provide.decorator
  19. $provide.decorator("$mdDialog", function ($delegate) {
  20. // Get a handle of the show method
  21. var methodHandle = $delegate.show;
  22.  
  23. function decorateDialogShow () {
  24. var args = angular.extend({}, arguments[0], { hasBackdrop: false })
  25. return methodHandle(args);
  26. }
  27.  
  28. $delegate.show = decorateDialogShow;
  29. return $delegate;
  30. });
  31. });
  32.  
  33. var dialogFactory = function($mdDialog) {
  34. var options = {};
  35. return {
  36.  
  37. create: function(conf) {
  38. var preset = $mdDialog.alert()._options; //get defaults
  39. var newOptions = angular.extend(preset, conf, options);//extend with yours
  40. $mdDialog.show(newOptions);
  41. },
  42. //toggle various props
  43. setProp: function(prop, val) {
  44. options[prop] = val;
  45. }
  46. };
  47.  
  48. };
  49.  
  50. $scope.toggleBackdrop = function() {
  51. $scope.backdrop = !$scope.backdrop;
  52. //here we change the state of the service internal var
  53. dialogService.setProp('hasBackdrop', $scope.backdrop);
  54. };
  55. $scope.showDialogViaService = function(ev) {
  56. //here we fill in the needed params of the modal and pass to the service
  57. var obj = {
  58. 'title': 'title',
  59. 'content': 'content',
  60. 'ok':'Ok!'
  61. };
  62. dialogService.create(obj);
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement