简体   繁体   English

Angular js Enter按下进入下一页

[英]Angular js Enter keypressed to go to next page

I am new to Angular JS, I am currently attempting to make a hybrid web app. 我是Angular JS的新手,我目前正在尝试制作一个混合Web应用程序。 I need to use some sort of key pressing function in which when i click enter on an input tag it goes to the next page.So far i have this below: 我需要使用某种按键功能,当我单击输入标签上的回车键时,它会转到下一页。到目前为止,我的操作如下:

 <label class="item item-input" style="width: 80%; margin:0 auto;">
    <input ng-model="name" type="text" placeholder="Enter your name"> </input>
  </label>    

You can use the ng-keypress directive. 您可以使用ng-keypress指令。 https://docs.angularjs.org/api/ng/directive/ngKeypress https://docs.angularjs.org/api/ng/directive/ngKeypress

So on your input , add ng-keypress="redirectMe($event)" 因此,在您的input ,添加ng-keypress="redirectMe($event)"

In your controller, 在您的控制器中

$scope.redirectMe = function(evt){
    if (evt.which === 13) {  $location.path( "/yournextpage" );  }
}

You can use a directive 您可以使用指令

HTML: HTML:

<button ng-enter="doAction(namePage)" ></button>

Github repository https://gist.github.com/EpokK/5884263 Github仓库https://gist.github.com/EpokK/5884263

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM