Utilizing Angular Material for distinctive user input values in Angular

How can I ensure that only the input field in which a user is typing gets populated, rather than all the input fields below it?

  <ng-container matColumnDef="branch_code">
    <mat-header-cell *matHeaderCellDef mat-sort-header>Enter Branch Code</mat-header-cell>
    <mat-cell *matCellDef="let row">
      <input matInput placeholder="Enter Branch Code" [(ngModel)]="branchCode">
      <mat-icon (click)="gotoWorkstationDetails()" >arrow_forward</mat-icon>
    </mat-cell>
  </ng-container>

I have successfully retrieved the input value in my ts file.

Please refer to the screenshot for reference. The issue is that all input fields are getting populated with '213', whereas only the active input field should display the value entered by the user. https://i.sstatic.net/JH6pw.png

import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { MatPaginator, MatTableDataSource, MatSort } from '@angular/material';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Router } from '@angular/router';

@Component({
  selector: 'app-workstation',
  templateUrl: './workstation.component.html',
  styleUrls: ['./workstation.component.scss']
})
export class WorkstationComponent implements OnInit {

  title = 'Workstation';


  displayedColumns = ['name', 'mac_address', 'address', 'branch_code'];
  dataSource = new MatTableDataSource();
  @ViewChild(MatSort) sort: MatSort;
  @ViewChild(MatPaginator) paginator: MatPaginator;
  loading = false;
  branchCode;

  constructor( private http: HttpClient, public router: Router ) { }

  ngOnInit() {
    this.dataSource.paginator = this.paginator;
    this.dataSource.sort = this.sort;
    this.loading = true;
    this.http.get<Array<any>>('/api/workstations').subscribe(data => {
      this.dataSource.data = data;
      this.loading = false;
    },
    err => {
      this.loading = false;
    });
  }

  applyFilter(filterValue: string) {
    filterValue = filterValue.trim();
    filterValue = filterValue.toLowerCase();
    this.dataSource.filter = filterValue;
  }

  gotoWorkstationDetails() {
    console.log(this.branchCode);

    this.loading = true;
    this.http.get<Array<any>>(`/api/branches/${this.branchCode}/workstations`).subscribe(data => {
      const branchDetail = data;
      this.router.navigate(['workstation/' + this.branchCode]);
      console.log(branchDetail);
      this.loading = false;
    },
      err => {
        this.loading = false;
      });
  }



}

Answer №1

Custom Data Column

Introduce an additional data column named branchCode in the table :

<ng-container matColumnDef="branch_code">
    <mat-header-cell *matHeaderCellDef mat-sort-header>Enter Branch Code</mat-header-cell>
    <mat-cell *matCellDef="let row">
        <input matInput placeholder="Enter Branch Code" [(ngModel)]="row.branchCode">
        <mat-icon (click)="gotoWorkstationDetails()">arrow_forward</mat-icon>
    </mat-cell>
</ng-container>

In this scenario, the branchCode is linked to all inputs.

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

What is the best way to enable autocomplete in vscode when using a function in TypeScript that returns a union type?

Is there a way to improve editor autocomplete when calling a function that returns a union type? For instance, in the given code snippet, after invoking getProperty<ColorfulOrCircle>() (line 14), the variable b should display the accessible properti ...

Having trouble installing sub npm dependencies for a private npm module

I've created an npm private repository using Sinopia and published an app that is a complete end-to-end application built with Angular2 on the UI side. The package.json file contains dependencies such as @angular/core and animations. However, when I ...

Exploring TypeScript methods for manipulating Apollo Client query results that have been transformed into props

After following a blog tutorial on GraphQL, I successfully integrated my GraphQL query with a React component to display the returned results. Everything seemed to be working fine as I could log this.props. However, when I tried to access individual data ...

Discovering dependencies for the Tabulator library can be achieved by following these

Can anyone provide me with a complete list of dependencies for Tabulator 4.2? I have already reviewed the package.json file, but it only contains devDependencies. ...

What is the best way to transfer image files into a specific folder?

I am currently in the process of developing a ReactJS web application. My goal is to upload images to a specific folder and then store the file name in the database for future use. Everything seems to be working smoothly up to this point, but I am facing ...

Can we confidently disregard React's caution regarding using the useState hook conditionally if only the parameter changes based on a condition?

In my React app, I am working on creating a calendar date selection function component to assign days to schedules. My goal is to pre-populate the calendar with existing data so users can modify it as needed. Here is what I have implemented so far: const ...

Utilizing interpolation in Angular to apply CSS styling to specific sections of a TypeScript variable

Suppose I have a variable called data in the app.component.ts file of type :string. In the app.component.html file, I am displaying the value of data on the UI using string interpolation like {{data}}. My question is, how can I apply some css to specific ...

Angular 13's APP_INITIALIZER doesn't wait as expected

Recently, I have been in the process of upgrading from okta/okta-angular version 3.x to 5.x and encountered an unexpected bug. Upon startup of the application, we utilized APP_INITIALIZER to trigger appInitializerFactory(configService: ConfigService), whi ...

Primary source for recurring components with the @SkipSelf decorator

Trying to understand the inner workings of Angular's dependency injection system, it seems that the component instance tree is traversed to locate the first occurrence of the specified provider, giving priority to ElementInjector over ModuleInjector ( ...

The autocomplete feature is now bypassing any text that comes after the #

return this.http.get(Configs.BASE_PATH + 'getTaxRates' + query + '&ts='+ Date.now()); query = "? The problem I'm encountering is related to my search query: 303 E 14 mile Rd, #305, Clawson, MI 48017. This ...

Signal a return type error when the provided element label does not correspond with an existing entity

I am working on a component that accepts three props: children (React elements), index, and label. The goal is for the component to return the child element at a specific index when index is passed, and to return the element with a specific label when la ...

Who is responsible for the addition of this wrapper to my code?

Issue with Sourcemaps in Angular 2 TypeScript App Currently, I am working on an Angular 2 app using TypeScript, and deploying it with the help of SystemJS and Gulp. The problem arises when I try to incorporate sourcemaps. When I use inline sourcemaps, eve ...

Inversify employs dependency injection similarly to how Angular utilizes TypeScript decorators

Today I made the switch from a js electron project to typescript and found myself wondering about the equivalent of angular's dependency injection. Since Angular Universal is still in its early stages and lacks documentation on using it with electron ...

Tips for individually assigning Fastify decorators within various plugins?

I'm encountering issues with typing decorators in two separate plugins (scopes): import Fastify, { FastifyInstance } from 'fastify' const fastify = Fastify() // scope A fastify.register((instance) => { instance.decorate('utilA&apo ...

Exploring new ways to customize Nebular styles within an nb-user tag

I've been struggling to adjust the font-weight and border-radius of a nb-user tag without any luck. I attempted to add a class and make changes in the .scss file, but nothing seemed to work This is the HTML <div class="teachers-box" *ngF ...

I am attempting to store the primary array in local storage, but unfortunately, the value is not being saved within the React context API

I attempted to store the main array in local storage and retrieve it as global state, but I am facing an issue where the data is not being saved in the local storage. This file represents my context. import { createContext, useReducer, ReactNode, FC, use ...

steps for signing in to garmin account with javascript

Attempting to set up an Oauth1 login for Garmin using Angular2 and standard http calls, but encountering a pre-flight OPTIONS call error on the initial request to oauth/request_token path. It seems like CORS is not enabled or something similar. Has anyone ...

Encountering ExpressionChangedAfterItHasBeenCheckedError while using Angular 4 data loading service for forms

Currently, I am fetching data from a REST API to populate radio buttons dynamically in a form. The Submit button is disabled until the form is valid. However, due to the delayed data retrieval process, the form's validity changes causing an error know ...

Creating an array that exclusively contains numbers using anonymous object export: A step-by-step guide

I am struggling with a record that is designed to only accept values of type number[] or numbers. This is how it is structured: type numberRecords = Record<string,number[]|number>; I ran into an error when trying this: export const myList:numberRec ...

Can you provide any instances of Angular2 projects with intricate routing, specifically with version 2.0.0-rc.1?

Currently, I am in the process of building a web application with angular2 (2.0.0 rc 1) and encountering obstacles due to the insufficient documentation, especially when it comes to establishing intricate routing. Since version 2.0.0 was just released app ...