如何在执行 Html 标记时重置 angular 范围变量?

How to reset the angular scope variable when the Html tag gets executed?

嘿,我有一个变量绑定到我的范围,


$scope.isSuccess = {
       invalidPhone : false
}

我正在使用跨度在变量为真时显示消息...

<form name = "myForm">
    <span ng-if="isSuccess.invalidPhone && myForm.$submitted">
          Please enter valid phone no.
    </span>
</form>

现在我在提交表单时调用 Js 方法..它验证 phone 数字并设置

$scope.isSuccess.invalidPhone = true 

仅当不正确时.

现在我想在执行 span 将此变量的值重置为 false。怎么做 ?谢谢

使用ng-change指令更新标志的状态:

<form name = "myForm">
    <input name="phoneNumber" ng-model="data.num" type="text" 
           ng-change="updateStatus(data.num)" /> 
    <span ng-if="isSuccess.invalidPhone && myForm.$submitted">
          Please enter valid phone no.
    </span>
</form>

每次用户更改phone号码时,都会调用函数:

$scope.updateStatus = function(num) {
    //Check phone number here
});

有关详细信息,请参阅