Search code examples
angularjsangularjs-scopeangularjs-material

Pass data with one way binding to md dialog


I want to pass data to an md dialog, and if I change that data inside the md dialog controller, it should not reflect that change in the parent controller of the md dialog.

vm.openAddWorkstreamDialog = () => $mdDialog.show({
   templateUrl: 'main/my-dialog/my-dialog.html',
   controller: 'MyDialogController',
   bindToController: true,
   clickOutsideToClose: true,
   locals: {
     data_in_dialog: data_in_parent
   }
});

now I want to achieve the behavior that if I make any change to the data_in_dialog object inside the MyDialogController, it should not change the data_in_parent object in the parent controller. Currently if I make any change in the data_in_dialog object(inside MyDialogController) it also changes the data_in_parent(which is present in the parent controller of the md dialog)


Solution

  • Use angular.copy inside MyDialogController

    $scope.varInsideDialogController = angular.copy(data_in_dialog);