点击进入Angular JS后获取价值

时间:2016-03-09 07:52:59

标签: javascript angularjs

我想在输入密钥后获得输入值..

我的xhtml看起来像

                        <div class="medium-12 columns">
                            <input name="verificationCode" ng-enter="enteredVerificationCode()" ng-model="user.verificationCode" type="text" id="verificationCode" placeholder="Enter Verification Code Here"  />
                            <div ng-messages="formSubmitted &amp;&amp; signupForm.email.$error">
                                <div ng-message="required" class="error">Verification Code is required.</div>
                            </div>
                        </div>

因为它在我的signupCtrl中,我的控制器看起来像:

Controllers.controller("signupCtrl", function($scope, $rootScope, restservice, $cookies) {
$scope.enteredVerificationCode=function(){
    console.log($scope.user.verificationCode);
}

}

2 个答案:

答案 0 :(得分:0)

您可以将其包装在表单标记中。

<form ng-submit="enteredVerificationCode()">
    <div class="medium-12 columns">
        <input name="verificationCode" ng-model="user.verificationCode" type="text" id="verificationCode" placeholder="Enter Verification Code Here"  />
        <div ng-messages="formSubmitted &amp;&amp; signupForm.email.$error">
            <div ng-message="required" class="error">Verification Code is required.</div>
        </div>
    </div>
</form>

答案 1 :(得分:0)

您可以使用ng-Keypress检测击键,并查找回车键(13)以触发 <p class="sent">abc</p> <textarea id="write">abc</textarea>功能。

enteredVerificationCode()