javascript - ngModel does not update parent object -
i try make directive using requires ngmodel
manage coords object ({x: number, y: number}
).
my problem when update value of in directive, works fine directive, parent scope data comes not updated.
in directive here content of link
function (only part manages ngmodel) :
ngmodel.$render = function() { console.log('render'); scope.top = ngmodel.$viewvalue.top; scope.left = ngmodel.$viewvalue.left; }; // transform model value view value // have x, y coords (of center) , need transform them top, left position ngmodel.$formatters.push(function(modelvalue) { console.log('> view'); if (modelvalue) { return { top: modelvalue.y - scope.pointer.size / 2, left: modelvalue.x - scope.pointer.size / 2 }; } return modelvalue; }); // transform view value model value // have top, left position , need transform them x, y coords (of center) ngmodel.$parsers.push(function(viewvalue) { console.log('> model'); if (viewvalue) { return { x: viewvalue.left + (scope.pointer.size / 2), y: viewvalue.top + (scope.pointer.size / 2) }; } return viewvalue; });
there drag'n'drop feature changes $viewvalue
, propagate (when element dropped) :
scope.$apply(function () { ngmodel.$setviewvalue({ top: scope.top, left: scope.left }); });
and directive call in parent :
<img-pointer data-ng-repeat="answer in graphicquestionctrl.answer" data-ng-model="answer"> </img-pointer>
the value in graphicquestionctrl.answer
seems never updated.
i have removed isolated scope directive img-pointer
have read blocks update of parent, not fix problem.
Comments
Post a Comment