服务未响应表单提交值

时间:2019-04-22 16:07:25

标签: angular typescript service

这是我的read.html,其中填写并提交了表单。

  <form class="mt-3 text-center" (ngSubmit)="onSubmit()">
              <div class="text-center">
                <input type="text" name="barcode" class="form-control text-center mt-2" [(ngModel)]="barcode" placeholder="Barcode">
              </div>
            </form>

这是我的read.ts,在提交表单之后,在其中调用服务并返回信息。

 constructor(private ticketlineservice: TicketlineService, 
    private activatedRoute: ActivatedRoute) {
      this.activatedRoute.queryParams.subscribe(params => {
        this.codEspec = params['CodEspec'];
        this.DiaHoraEspecs = params['DiaHoraEspecs'];
    });
     }

  ngOnInit() {

  }

  onSubmit(){      
    console.log(this.barcode,this.codEspec,this.DiaHoraEspecs );
    this.ticketlineservice.CheckTicket(this.barcode, this.codEspec, this.DiaHoraEspecs).subscribe(reads => {
      this.reads = reads[0].Tickets;
      console.log(reads);
  });
}

我正在调用的服务的功能。其他两个参数(codEspec和DiaHoraEspecs)来自先前的网址。

 CheckTicket(barcode, codEspec, diaHoraEspec):Observable<Ticket[]>{
    //get todos os eventos
    return this.http.get<Ticket[]>(`${this.url_node_tickets}${this.barcode}${this.codEspec}${this.diaHoraEspec}`, httpOptions);
  }

问题::控制台日志中的所有值均显示且正确,但在url中,条形码不变。

1 个答案:

答案 0 :(得分:1)

CheckTicket(barcode, codEspec, diaHoraEspec):Observable<Ticket[]>{
    //get todos os eventos
    return this.http.get<Ticket[]>(`${this.url_node_tickets}${this.barcode}${this.codEspec}${this.diaHoraEspec}`, httpOptions);
  }

${this.barcode}${this.codEspec}${this.diaHoraEspec}

我认为您需要删除其中的this(类引用)并使用函数的参数吗? ${barcode}${codEspec}${diaHoraEspec}