我们如何在Android上的Angular中获取keypress事件及其价值? 我使用phonegap Cordova Angular JS
<form name="myForm">
<input type="search" name="userName" ng-model="user" class="search-input" style="width: 96%; margin: 6px auto 6px auto;" placeholder="Начните вводить название">
</form>
</div>
</div>
user = {{user}}
非常感谢任何帮助。
答案 0 :(得分:2)
<form name="myForm">
<input type="search"
name="userName"
ng-model="user"
ng-keypress="yourMethod(user)" class="search-input"
style="width: 96%; margin: 6px auto 6px auto;"
placeholder="Начните вводить название">
</form>
user = {{user}}
<强>更新强>
<input type="search" name="userName" ng-model="user" ng-change="getValue(user)" class="search-input" style="width: 96%; margin: 6px auto 6px auto;" placeholder="Начните вводить название">
我的控制器$scope.getValue = function (calll) { alert(calll); }
答案 1 :(得分:0)
<form name="myForm">
<input type="search" name="userName" ng-keypress="getValue($event) ng-model="user" class="search-input" style="width: 96%; margin: 6px auto 6px auto;" placeholder="Начните вводить название">
</form>
</div>
</div>
user = {{user}}
In controller :-
$scope.getValue = function (event) { console.log(event) }
答案 2 :(得分:0)
答案 3 :(得分:0)
在这种情况下,创建指令属性可能会更好。
angular.module('inputDirective', [])
.directive("mydirective", function() {
var directive = {};
directive.restrict = 'A';
directive.scope = {};
directive.link = function(scope, element, attrs, controller) {
//read the text typed in the div
function read() {
var html = element.html();
}
//do this whenever someone starts typing
element.bind("keyup", function() {
scope.$apply(read);
});
}
return directive;
})
在html中将属性添加到标记。
<input mydirective type="search" name="userName" ng-model="user" class="search-input" style="width: 96%; margin: 6px auto 6px auto;" placeholder="Начните вводить название">