How to get input value search box and enter it in AngularJS component using Enter key ? Last Updated : 02 Mar, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will see how to get an input value entered in the search box using Enter key in AngularJS. To implement a search component in AngularJS that calls the function whenever the user presses the enter key(keyCode = 13) and then does some relatable task from the user input. This can be achieved easily using the keyup event. Here for styling purposes, bootstrap and font awesome is being used. We need a basic input tag that will have a keyup event that calls an onSubmit($event) function and pass the event as an argument. The $event gives us different types of property but we are going to take the help of keyCode which tells us which key is pressed by the user. We use the keyCode to check whether the user has pressed the Enter key whose code is 13. Once the Enter key is pressed you can perform the task that you want such as searching from a list or passing the search element to another component. For simplicity, We have created a small array that checks for the search element inside the array and outputs the results. Example: This example describes the process for getting the input value entered in the search box using Enter key in AngularJS. Â app.component.html HTML <div class="container"> <div class="row"> <div class="col-md-4"></div> <div class="col-md-4"> <h1>GeeksforGeeks</h1> <h3> How to get input value search box and enter it in AngularJS component using Enter key? </h3> <h4>Programming Languages</h4> <div class="searchBox"> <input (keyup)="onSubmit($event)" [(ngModel)]="searchValue" type="text" id="searchKey" class="form-control" placeholder="Search Box" /> </div> <div *ngIf="condition; then block1; else block2"> </div> <ng-template #block1> <i class="fa fa-spinner fa-spin" aria-hidden="true"> </i> Searching your results for <strong>{{prevText}}</strong> </ng-template> <ng-template #block2> <h6>{{res_cnt}} Search Result Found <span *ngFor="let lang of res_list"> <strong>{{lang}}, </strong> </span> </h6> </ng-template> </div> </div> </div> app.component.css CSS .searchBox { margin: 20px 0; } input { width: 20%; padding: 10px; text-align: center; } h1 { color: green; } app.component.ts JavaScript import { Component } from '@angular/core'; import { AbstractControl, FormBuilder, FormGroup } from '@angular/forms'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { searchValue: any; condition: boolean = false; prevText: string = ''; list_lang: any[] = ['java', 'c++', 'python', 'c', 'javascript']; res_list = []; res_cnt: number = 0; onSubmit($event: KeyboardEvent) { if ($event.keyCode === 13) { this.condition = true; this.prevText = this.searchValue; this.res_cnt = 0; this.res_list = []; setTimeout(() => { this.condition = false; for (let i = 0; i < this.list_lang.length; i++) { if (this.list_lang[i] === this.prevText.toLowerCase() || this.list_lang[i].startsWith(this.prevText)) { this.res_cnt += 1; this.res_list.push(this.list_lang[i]); } } }, 3000); this.searchValue = null; } } } app.module.ts JavaScript import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { AppComponent } from './app.component'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, FormsModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { } Output: Â Comment More infoAdvertise with us Next Article How to get input value search box and enter it in AngularJS component using Enter key ? A amitsingh48 Follow Improve Article Tags : AngularJS Technical Scripter 2020 AngularJS-Questions Similar Reads Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co 11 min read Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance 10 min read Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact 12 min read Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and 9 min read 3-Phase Inverter An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power 13 min read Polymorphism in Java Polymorphism in Java is one of the core concepts in object-oriented programming (OOP) that allows objects to behave differently based on their specific class type. The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity ca 7 min read What is Vacuum Circuit Breaker? A vacuum circuit breaker is a type of breaker that utilizes a vacuum as the medium to extinguish electrical arcs. Within this circuit breaker, there is a vacuum interrupter that houses the stationary and mobile contacts in a permanently sealed enclosure. When the contacts are separated in a high vac 13 min read CTE in SQL In SQL, a Common Table Expression (CTE) is an essential tool for simplifying complex queries and making them more readable. By defining temporary result sets that can be referenced multiple times, a CTE in SQL allows developers to break down complicated logic into manageable parts. CTEs help with hi 6 min read Spring Boot Interview Questions and Answers Spring Boot is a Java-based framework used to develop stand-alone, production-ready applications with minimal configuration. Introduced by Pivotal in 2014, it simplifies the development of Spring applications by offering embedded servers, auto-configuration, and fast startup. Many top companies, inc 15+ min read Python Variables In Python, variables are used to store data that can be referenced and manipulated during program execution. A variable is essentially a name that is assigned to a value. Unlike many other programming languages, Python variables do not require explicit declaration of type. The type of the variable i 6 min read Like