Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Dialog with Angular Form

I have an Angular app and am using Angular-Material among other components. Is it possible to open an Angular Tab Dialog with a TemplateUrl being lazy loaded which contains an Angular form? How would you reference this form if at all possible? Here is some code I use to open the dialog:

    $scope.showTabDialog = function(ev) {

        $mdDialog.show({
                controller: DialogController,
                templateUrl: 'pages/properties/tabDialog.tmpl.html',
                parent: angular.element(document.body),
                targetEvent: ev,
                clickOutsideToClose:true
            })
            .then(function(answer) {
                $scope.status = 'You said the information was "' + answer + '".';
            }, function() {
                $scope.status = 'You cancelled the dialog.';
            });
    };

Any Help would be appreciated, thank you

like image 415
johan Avatar asked Feb 03 '16 10:02

johan


People also ask

How do you pass data in angular material dialog?

We can pass data to the dialog component by using the data property of the dialog configuration object. As we can see, the whole data object initially passed as part of the dialog configuration object can now be directly injected into the constructor.

What is MatDialog in angular?

MatDialog creates modal dialogs that implements the ARIA role="dialog" pattern by default. You can change the dialog's role to alertdialog via MatDialogConfig . You should provide an accessible label to this root dialog element by setting the ariaLabel or ariaLabelledBy properties of MatDialogConfig .

How do I get data from MatDialog?

You can pass any kind of data to the component by adding data to the MatDialog's open() options. }, }); You can retrieve the data by injecting MAT_DIALOG_DATA in the opened component.

How do I stop MatDialog from closing when I click outside?

How To Prevent MatDialog From Closing When Clicked Outside. By default, you could close a material dialog box by clicking outside dialog box element or by pressing the esape key. Angular Material comes with a built-in property called disableClose the prevents this behavior.


1 Answers

Not sure I understand your question correctly but for basic use, pass in your context to locals and return your info to $mdDialog.hide

    $mdDialog.show({
      targetEvent: $event,
      template: dialogContent,
      controller: 'DialogController',
      locals: { info: $scope.info }
    }).then(function(info) {
        if(info) {
          $scope.info.userName = info.userName;      
        }
      });

...

$mdDialog.hide(info);

See this Code Pen:

http://codepen.io/anon/pen/BjqzJR

like image 122
malix Avatar answered Oct 26 '22 07:10

malix