Search code examples
javascriptangularjshybrid-mobile-app

Can I add a variable or a function in a mdDialog?


I want to add a variable or a function to my mdDialog. Im not to sure on how to create a custom mdDialog, Im new to angularjs.

This is my mdDialog:

vm.dialog_up = function() {
     vm.dis = true;
      alert = $mdDialog.alert()
        .title('Attention, ')
        .content('Do you want to edit your Information?')
        .ok('Close');


      $mdDialog
          .show( alert )
          .finally(function() {
            alert = undefined;
          });
    }

I want to maybe add a function to the .ok button.


Solution

  • JavaScript is a very liberal language and it allows you to add properties and methods to objects. For example:

     var modal = {};
    
     modal.x = 5;//this assigns the value of `5` to the newly attached property `x`
    
     modal.testMethod = function() {
         //Do something here
     }
    

    PS: Though personally, I think that modifying framework objects can cause side effects.