Angularjs click clear button inside input but no effect to binded json object

Viewed 21

As title. I have a page with several inputs with type="text", and set them with clear buttons generated by the js code:

function SetClearButtonInTextBox(Callback) {
    if (!window.document.documentMode) {
        $("input").each(function () {
            var im = $(this);
            if (!$(this).parent().hasClass("text-input-wrapper") && !$(this).hasClass("btn")) {
                $(this).wrap("<div class='text-input-wrapper'></div>");
                $(this).after("<button class=\"Covered\" type=\"button\">&times;</button>");
            }
            $(this).closest("div.text-input-wrapper").find("button").mousedown(function () {
                im.val("");
                im.change();
                //return false;
            });
        });
    }
}

And my inputs like this:

<input name="ModelA" ng-model="dl.ModelA" ng-change="ClearText(this,dl.ModelA);" value=""/>
<input name="ModelB" ng-model="dl.ModelB" ng-change="ClearText(this,dl.ModelB);" value=""/>

And I made the "ClearText" function as:

$scope.ClearText=function(target, ngModelTo){
            if (target.target.value == "") {
                ngModelTo = "";
            }
        }

I want when I click the clear button inside input, the binded value and the textbox will also be cleared, but I found that only my textbox is cleared but the binded value isn't. Could someone guide me to make it?

0 Answers
Related