我有一个输入文本框,我希望当用户在文本框中输入值并失去焦点时。我想从api值验证此值,并需要在输入框下方显示相应的消息。我怎么能在角js
答案 0 :(得分:0)
您可以使用ng-blur
指令。
<input type="text" ng-blur="ValidateBlur()" />
https://plnkr.co/edit/hy2sCVjvVqBrm1WSdiBl?p=preview
模块/控制器设置代码:
var app = angular.module("testApp", []);
app.controller("DarrenController", function($scope) {
$scope.Text = "Testing...";
$scope.ValidateBlur = function() {
alert('Validating');
}
});
<强> HTML:强>
<body ng-app="testApp">
<div ng-controller="DarrenController">
<input type="text" ng-blur="ValidateBlur()" />
</div>
</body>
答案 1 :(得分:0)
// HTML
<input type="text" ng-model="search" placeholder="Search ... " ng-focus="focusMsg()" ng-blur="blurMsg()">
//控制器
$scope.focusMsg = function () {
console.log('Focus');
}
$scope.blurMsg = function () {
console.log('Blur');
}