javascript - Angular send only changed fields to update method -


i have save method. on click of save want send changed fields instead of since have more 50 fields on page. heavy send fields everytime.

api.admin.update({     obsoletedate : adminedit.obsoletedate.$dirty== true?$scope.editobsoletedate:""       }); 

above checking field dirty value true or false. don't want send value empty if value not changed. other way that?

i build object changed properties , send object. make copy of original object before editing , use compare, adapt $dirty. along these lines:

function getupdateobject(orig, current) {     varchanges = {};      (var prop in orig) {         if (prop.indexof("$") != 0 && orig[prop] !== current[prop]) {             varchanges[prop] = current[prop];         }     }     return varchanges ; }; 

then update code calls function new object changes, assigns whatever primary key i'm working object , sends server. have no idea end is, you'll need http patch in order work. this:

function save() {     var changes = getupdateobject(vm.orig, vm.current)     changes.id = vm.orig.id     $http.patch("http:/serviceuri.com (" + changes.id + ")", changes).then(...) } 

i pulled code out of app uses odata , modified bit answer, of code exists in service use of odata interactions.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -