Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.config(['$mdDialogProvider', function($mdDialogProvider){
- console.log($mdDialogProvider);
- // ^ $get/addMethod/addPreset/setDefaults
- var defaults = {
- options: function(){
- return {
- hasBackdrop: false
- }
- }
- }
- $mdDialogProvider.setDefaults(defaults);
- }]);
- $provide.decorator(name, decorator);
- .config(function ($provide) {
- // Decorate the $mdDialog service using $provide.decorator
- $provide.decorator("$mdDialog", function ($delegate) {
- // Get a handle of the show method
- var methodHandle = $delegate.show;
- function decorateDialogShow () {
- var args = angular.extend({}, arguments[0], { hasBackdrop: false })
- return methodHandle(args);
- }
- $delegate.show = decorateDialogShow;
- return $delegate;
- });
- });
- var dialogFactory = function($mdDialog) {
- var options = {};
- return {
- create: function(conf) {
- var preset = $mdDialog.alert()._options; //get defaults
- var newOptions = angular.extend(preset, conf, options);//extend with yours
- $mdDialog.show(newOptions);
- },
- //toggle various props
- setProp: function(prop, val) {
- options[prop] = val;
- }
- };
- };
- $scope.toggleBackdrop = function() {
- $scope.backdrop = !$scope.backdrop;
- //here we change the state of the service internal var
- dialogService.setProp('hasBackdrop', $scope.backdrop);
- };
- $scope.showDialogViaService = function(ev) {
- //here we fill in the needed params of the modal and pass to the service
- var obj = {
- 'title': 'title',
- 'content': 'content',
- 'ok':'Ok!'
- };
- dialogService.create(obj);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement