Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

225
Visualizações
failing to load a simple onclick event to display textbox value in angular

I have a simple html view where an order number is entered but I am failing to get the value of the textbox in the onClick event

HTML

<div class="row">
  <div class="col-lg-12">
    <nb-card>
      <nb-card-header>Place Order</nb-card-header>
      <nb-card-body>
        <input type="text" id="txtOrderNumber" nbInput fullWidth placeholder="Order Number">
        <div class="full-name-inputs">
          <input nbInput fullWidth  placeholder="Date Placed" [nbDatepicker]="datePlaced">
          <nb-datepicker #datePlaced></nb-datepicker>
          <input nbInput fullWidth placeholder="Date Expected" [nbDatepicker]="dateExpected">
          <nb-datepicker #dateExpected></nb-datepicker>
        </div>
        <input type="text" nbInput fullWidth shape="rectangle" placeholder="Supplier">
        <input type="text" nbInput fullWidth shape="semi-round" placeholder="Unit">
        <input type="text" nbInput fullWidth shape="round" placeholder="Quantity">
        <input type="text" nbInput fullWidth placeholder="Total Amount" disabled/>
        <textarea rows="5" nbInput fullWidth shape="round"  placeholder="Order Description"></textarea>

       <button  (click)="ShowRawMaterials()" nbButton>Click Me</button>
      
      </nb-card-body>

    </nb-card>
  </div>

</div>

Typescript

import { Component } from '@angular/core';
import { NbDateService } from '@nebular/theme';
/*import {AfterViewInit, Component, ElementRef, ViewChild} from '@angular/core';*/

@Component({
  selector: 'ngx-form-inputs',
  styleUrls: ['./place-order.component.scss'],
  templateUrl: './place-order.component.html',
})
/*export class PlaceOrderComponent implements AfterViewInit {
 @ViewChild('txtOrderNumber') txtOrderNo: ElementRef;*/
 export class PlaceOrderComponent {
  starRate = 2;
  heartRate = 4;
  radioGroupValue = 'This is value 2';

    min: Date;
    max: Date;

    constructor(protected dateService: NbDateService<Date>) {
      this.min = this.dateService.addDay(this.dateService.today(), -5);
      this.max = this.dateService.addDay(this.dateService.today(), 5);
    }
 ShowRawMaterials()  {
      
         var inputValue = (<HTMLInputElement>document.getElementById(txtOrderNo)).value;
         alert(inputValue);
        }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can find demo in this StackBlitz Link

You can use template reference variable like this in html inside input orderNo..

<input
  #orderNo
  type="text"
  id="txtOrderNumber"
  nbInput
  fullWidth
  placeholder="Order Number"
/>
 <button (click)="ShowRawMaterials(orderNo)" nbButton>Click Me</button>

and then you can use it inside component.ts file like this...

ShowRawMaterials(orderNo) {
  console.log(orderNo?.value);
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda