Marc Bachmann
Marc Bachmann

Reputation: 1

angular md-dialog using controller scope

I open a dialog with mdDialog when checking a checkbox (in the example checkbox 1). Within this dialog there are several input fields, which should be connected via ng-modell to a controller - but it seems, that is not the scope used by the main controller (in the example myCtrl).

How can I use the same scope in the dialog and myCtrl? I tried locals to access the parent scope, but this didn't work.

Here is the plunker:

[https://plnkr.co/edit/9biRK5oskpQRhRWyeHWd](https://plnkr.co/edit/9biRK5oskpQRhRWyeHWd)

Upvotes: 0

Views: 513

Answers (2)

Jedi
Jedi

Reputation: 11

Remove the loacals. It can use myCtrls scope.

<md-radio-group ng-model="dialog_radio1">

Then in the cancel function I was able to log the selected radio value from myCtrls' scope.

$scope.cancel = function () {
                        $mdDialog.cancel();
                        console.log($scope.dialog_radio1);
                        };

Upvotes: 0

Leibale Eidelman
Leibale Eidelman

Reputation: 3184

just pass the $scope to $mdDialog.show

$mdDialog.show({
    scope: $scope,
    controller: function () {
        // ...
    }
});

Upvotes: 2

Related Questions