Retrieving selected item values in Angular 2 using ng2-completer

Recently, I decided to experiment with a new autocompleter tool that is unfamiliar to me: https://github.com/oferh/ng2-completer. I successfully imported it and it seems to be functioning properly.

My current goal is to retrieve the values of the selected item once it has been chosen:

<ng2-completer [(ngModel)]="searchStr" 
[inputClass]="'form-control form-control-inline'"  [datasource]="getSelectedItemArray?" 
[minSearchLength]="0"></ng2-completer>

Selections :

 protected searchData = [
    { name: 'Bus UK LTD', address: 'Example', address2: 'Example2',
      pscode: '8497UK', ccode: '877SAD', veh1: '84A4DA', veh2: '846ASD', trail1: '486XSS', trail2: '8746SS' },
    ...
  ];


  constructor(private completerService: CompleterService) {
    this.dataService = completerService.local(this.searchData, 'name', 'name');
  }

To summarize - I select an item from a list which populates the input value, but then I want to access all the details of that selected item (such as name, address, etc.). How can I achieve this?

Answer №1

The searchStr model should contain the specified value in it

UPDATE

Include the following code snippet in your HTML file

(selected)="onItemSelected($event)"

In your typescript file:

onCountrySelected(selected: CompleterItem) {
        if (selected) {
             console.log(selected.title);
           }       
    }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I'm looking for a way to create a Redux thunk action creator that will return a promise. How

In my code, I have a primary thunk that is triggered by a button click. Within this thunk, I need to invoke another thunk and ensure it completes before proceeding. The second thunk returns a promise. Below is an excerpt of the code in question: export f ...

What is the best way to locate a particular JSON key value pair through JavaScript?

I'm in the process of creating a unique app that forecasts the weather for an upcoming event based on the city location specified. To achieve this, I am utilizing two APIs - one API provides an array of objects representing each event by an artist ent ...

Disabling the intellisense feature for locale suggestions in Monaco is recommended

Switch the keyboard language to a different one (in this case Japanese using alt + shift), and when typing in Monaco editor, an intellisense menu appears with options to remove and search. Monaco Editor Version: V0.33.0 https://i.stack.imgur.com/SIyeV.pn ...

Encountering an unhandled runtime error while importing the Client component into the server component: The JSON format is invalid, with the error message stating "undefined"

I've been attempting to create a basic counter component that increments the count of a state variable when a button is clicked. To achieve this, I created a separate file named Counter.tsx and placed it in the components folder at the root of my next ...

Angular6 dropdown menu malfunctioning---"The Angular6 dropdown menu is not functioning

I'm having an issue where clicking on a sidebar item does not open the menu as expected in my Angular 6 project. I'm unsure of how to troubleshoot and fix this problem. <li *ngIf="mUser.role.accountant !== true" class="nav-item dropdown" rout ...

What's causing the member to be undefined?

client.on('raw', (e) => { if (e.t === 'MESSAGE_REACTION_ADD' && e.d.message_id === '813150433651851265' && e.d.emoji.name === "✅" ) { const guild = client.guilds.cache.get(e.d.gui ...

reactjs: disable a specific eslint rule

I'm trying to figure out how to disable the "no-unused-vars" rule specifically for TypeScript interfaces. Here's a code snippet where I'm getting a warning: export type IKeoTableColumn<T> = { id: T; align: 'left' | ' ...

Exploring object data within Laravel blade templates is an essential skill in web development

Below is an example of how the data appears: [ { "id": 22528, "user_id": 25273, "non_sql": "{\"data\": {\"data_1\": \"4\", \"data ...

Unable to send parameters via URL when making an Ajax request in Rails

Struggling to pass a parameter through a URL in an Ajax request that's triggered by a confirmation dialog. Need the value of that parameter in my Rails controller upon successful request but can't seem to make it work. Tried the following code s ...

Tap into the live monitoring feature of angular-cli build

Is there a way to integrate custom functionality with angular-cli's build/watch command? ng build /w This command creates files and places them in the project's /dist folder I am looking to automatically copy the contents of the dist folder ...

React - the use of nested objects in combination with useState is causing alterations to the initial

After implementing radio buttons to filter data, I noticed that when filtering nested objects, the originalData is being mutated. Consequently, selecting All again does not revert back to the original data. Can anyone explain why both filteredData and orig ...

What is the best way to display my to-do list items within a React component

I'm working on a straightforward todo application using fastapi and react. How can I display my todos? I attempted to use {todo.data}, but it's not functioning as expected. Here is my Todos.js component: import React, { useEffect, useState } fro ...

Encountering issues with Typescript when using absolute paths

After updating a forked repository, I noticed that TypeScript is no longer recognizing absolute paths. Surprisingly, I have not made any changes to my tsconfig.json: { "compilerOptions": { "allowJs": true, "allowSyntheticDefaultImports": true, ...

Validating JSON arrays with RAML

My API RAML includes a query parameter called 'sfIds' that is of type array. I want to ensure that the elements within this array are always numeric, like [111, 222, 333] or [111]. Any non-numeric values in the array, such as [ABC,111], should no ...

The key property is present on the list item, yet the key warning persists

I have encountered various issues with this problem, but I am unable to pinpoint the exact cause. I am not extracting individual list items and simply displaying a UL with unique keys assigned to each item. However, when I log the results, I see something ...

Using React: implementing a spinner upon clicking a button and transitioning to a new screen when the animation finishes

I have noticed that there are existing answers on incorporating spinners during fetch requests completion. However, my query pertains to stopping the animation once it reaches completion after a timeout. Additionally, I am seeking advice on best practices ...

Guide on verifying Unicode input in JavaScript?

I am looking to create a form where the user can only input Khmer characters (Unicode characters) and display an alert if they input anything else. Khmer Name: <input type="text" class="namekh" name="namekh"> To achieve this, here is a snippet of m ...

Switch between different react components

When a component is opened, I want all other components to close. Whenever they are clicked, they will display a list. class ParentComponent extends Component{ constructor(props){ super(props) this.state= {...} } render(){ return( ...

Tips for accessing payment details from a stripe paymentElement component in a React application

Here is a basic code snippet for setting up recurring payments in Stripe: await stripe ?.confirmSetup({ elements, confirmParams: { return_url: url, }, }) After browsing through the documentation and the internet, I have two unanswere ...

What is the process for importing npm scoped packages with @ symbol in Deno?

Having some trouble with importing @whiskeysockets/baileys in Deno. Here's the code snippet I'm using: import * as a from "npm:@whiskeysockets/baileys"; console.log(a); When I try to run deno run main.ts, it throws the following error: ...