Javascript 在angularjs表单中添加简单的反垃圾邮件操作

Javascript 在angularjs表单中添加简单的反垃圾邮件操作,javascript,angularjs,Javascript,Angularjs,我有这样一个输入字段: <div class="form-group form-group-sm"> <label for="antispam" class="col-sm-2 control-label">1+1+5 = ? <span class="myForm_error" ng-show="myFormZR.antispam.$error.required">(requi

我有这样一个输入字段:

                <div class="form-group form-group-sm">
                    <label for="antispam" class="col-sm-2 control-label">1+1+5 = ? 
    <span class="myForm_error" ng-show="myFormZR.antispam.$error.required">(required field)</span>
<span ng-show="myFormZR.antispam.$dirty && IsMatch">BAD ANSWER</span></label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" name="antispam" placeholder="" required="required" ng-model="myForm.antispam" />
                    </div>
                </div>

它不起作用,当控制器被实例化时,提到的“错误答案”总是显示您的代码只运行一次。您需要将该代码放入该ng型号的$watch函数中:

$scope.$watch('myForm.antispam', function() {
  // that code
})

还要做大量的
console.log()
来调试您的代码,这样您就可以知道应用程序中发生了什么以及什么时候发生的事情了。

您能简要介绍一下您到底想做什么吗?我添加了测试代码,但它不起作用,提到的“错误答案”总是显示出来只是添加ng show=“myForm.antispam!=7”
$scope.$watch('myForm.antispam', function() {
  // that code
})