javascript - Using AngularJS "copy()" to avoid reference issues -


i'm displaying list of items, each of has "edit"-button next it. click on opens angular ui modal window , user can change properties of specific item.

now, bugged me when typing in edit-window, specific item in list of items reflected changes immediatly. wanted update when user clicked 'ok' in modal, , not change @ if user chose 'cancel'.

my workaround uses copy make a, well, copy of chosen item serves model view:

var modalinstance = $modal.open({     templateurl: 'scripts/app/views/editbond.html',     controller: function ($scope, $modalinstance, bond) {         $scope.bond = angular.copy(bond);         $scope.ok = function () {             $modalinstance.close($scope.bond);         };         $scope.cancel = function () {             $modalinstance.dismiss('cancel');         };     },     resolve: {         bond: function () {             return bond;         }     } }); 

is using angular.copy() appropriate avoid such issues? scope issue @ all?

yep, using angular.copy() absolutely appropriate here. if want more advanced might want checkout angular-history


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -