AngularJS ng-focus和ng-blur无法识别

时间:2015-08-02 20:07:04

标签: javascript angularjs forms input

我已经读过AngularJS应该允许您在输入标记中使用ng-focusng-blur作为默认控制器。但是,当我使用它时它给了我......

  

命名空间ng-focus未绑定...

我正在使用AngularJS 1.4.3,我认为它应该是最新版本。

这是我的代码:

<div class="input-boxes" ng-controller="formController">
    <form name="Form" ng-submit="submitForm()">
        <div class="required">
            <input type="text" name="user" placeholder="{{messages.inputEmail | langFilter}}" class="input-style" ng-model="inputs.email" ng-minlength="3" ng-pattern="form.pattern" required>
            <p class="error" ng-show="Form.user.$error.pattern && Form.user.$touched">&nbsp;{{messages.errorPattern | langFilter}}</p>
            <p class="error" ng-show="checkAccount">&nbsp;{{messages.errorAccount | langFilter}}</p>
            <input type="password" name="password" ng-model="inputs.password" placeholder="{{messages.inputPassword | langFilter}}" class="input-style" ng-focus: "">
        </div>

我想使用ng-focus/blur的原因是因为如果选择了密码字段,我想将$touched设置为false。 谢谢!

1 个答案:

答案 0 :(得分:-1)

使用ng-focus并告诉它将Form.user.$touched更新为false

<input type="password" name="password" ng-model="inputs.password" placeholder="{{messages.inputPassword | langFilter}}" class="input-style" ng-focus="Form.user.$touched = false">