Search code examples
javascriptangularjswebhybrid-mobile-app

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. 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>    

Solution

  • You can use the ng-keypress directive. https://docs.angularjs.org/api/ng/directive/ngKeypress

    So on your input, add ng-keypress="redirectMe($event)"

    In your controller,

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