[英]How to submit a form with “Enter” in AngularJS?
I have a search form without a submit button. 我有一个没有提交按钮的搜索表单。 How can I route to #!/result
, by pressing the enter key? 如何通过按Enter键路由到#!/result
?
HTML: HTML:
<form ng-controller="searchCtrl">
<input ng-href='#!/result' type="text" placeholder="Поиск">
</form>
JS: JS:
App.config(['$routeProvider',function($routeProvider){
$routeProvider
.when('/result',{
templateUrl:'../views/result.html',
controller:"searchCtrl",})
}]);
To submit a form with ENTER you need a submit button. 要使用ENTER提交表单,您需要一个提交按钮。 If you don't want one, a tricky way would be adding an invisible button in the form: 如果你不想要一个,一个棘手的方法是在表单中添加一个隐形按钮:
<form ng-submit="redirect()">
...
<input type="submit" style="visibility: hidden"/>
</form>
Note that I added a ng-submit call in the form: 请注意,我在表单中添加了ng-submit调用:
$scope.redirect = function() {
$location.href('/result');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.