How do we get the keypress event and its value in Angular on Android? I Use the phonegap Cordova Angular JS
如何在Android上获得按键事件及其值?我用的是电话
<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}}
Any help is really appreciated.
非常感谢你的帮助。
4 个解决方案
#1
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}}
UPDATE:
更新:
<input type="search" name="userName" ng-model="user" ng-change="getValue(user)" class="search-input" style="width: 96%; margin: 6px auto 6px auto;" placeholder="Начните вводить название">
And my controller $scope.getValue = function (calll) { alert(calll); }
我的控制器美元范围。getValue =函数(calll) {alert(calll);}
#2
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) }
#3
0
ng-keypress function available in angularjs,
在angularjs中可用的ng-keypress函数,
You can also use ng-keydown and ng-keyup in similar manner. FYI.
您还可以以类似的方式使用ng-keydown和ng-keyup。仅供参考。
For reference , ng-keypress tutorial
作为参考,ng-keypress教程
#4
0
Creating a directive attribute might work better in this case.
在这种情况下,创建一个指令属性可能会更好。
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;
})
In the html add the attribute to the tag.
在html中向标记添加属性。
<input mydirective type="search" name="userName" ng-model="user" class="search-input" style="width: 96%; margin: 6px auto 6px auto;" placeholder="Начните вводить название">
#1
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}}
UPDATE:
更新:
<input type="search" name="userName" ng-model="user" ng-change="getValue(user)" class="search-input" style="width: 96%; margin: 6px auto 6px auto;" placeholder="Начните вводить название">
And my controller $scope.getValue = function (calll) { alert(calll); }
我的控制器美元范围。getValue =函数(calll) {alert(calll);}
#2
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) }
#3
0
ng-keypress function available in angularjs,
在angularjs中可用的ng-keypress函数,
You can also use ng-keydown and ng-keyup in similar manner. FYI.
您还可以以类似的方式使用ng-keydown和ng-keyup。仅供参考。
For reference , ng-keypress tutorial
作为参考,ng-keypress教程
#4
0
Creating a directive attribute might work better in this case.
在这种情况下,创建一个指令属性可能会更好。
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;
})
In the html add the attribute to the tag.
在html中向标记添加属性。
<input mydirective type="search" name="userName" ng-model="user" class="search-input" style="width: 96%; margin: 6px auto 6px auto;" placeholder="Начните вводить название">