Problems $ scope mdDialog angularjs

3

Good morning guys!

I'm having trouble passing an array to an md-dialog.

Clicking on an edit button sends the array that is in the $ scope via locals to the md-dialog's controller so that I can change the data and save it. But the problem is that all the modification I make to the array inside the md-dialog is applied simultaneously to the array of the page that is behind the dialog (page that sent the data), even if I cancel the dialog. >

For example: I pass the multi-line array to the dialog, and if I remove a row from the array there in this dialog it also removes the array row from the submit page. It looks like they are linked and everything that happens in one repeats in the other even if I cancel the dialog. Dai when I come back in the edit array is without the line that was deleted before even having canceled the dialog.

Thanks for helping out.

Hugs!

    
asked by anonymous 04.02.2016 / 14:44

1 answer

2

Yes, they are connected, it's a feature of AngularJS, it's the root of how it works, MVVM.

If you want to make changes to your array within the scope of md-dialog and if this array must be the same as the parent scope, you can use angular.copy() to create a copy of the array and move it to md- dialog.

    
04.02.2016 / 16:24