Two subscribes in the same role?

Asked

Viewed 31 times

0

I have a function in Typescript where your return is directed to an input in formGroup, but I cannot use the same return in another field, only if you have the same name.

I need to use the return in HTML table and I can’t put one formControlName in a td

Requisition

case 'nomeProduto':
 params = params.set('cod', formGroup.controls['codigoProduto'].value);
 this.retornaNomeApi(NEGOCIUS_API + '/Pesquisa/RetornaNome', params)
     .subscribe(nome => formGroup.patchValue({
         nomeProduto: nome.result
      }));
break;

Input calling the function

<div class="col-md-2">
  <label>Código:</label>
    <div class="input-group">
    <!--Input que chama a função do nome do produto-->
      <input type="text" class="form-control" name="product" formControlName="codigoProduto" (keydown.tab)="this.formpesquisaservice.retornaNome('nomeProduto', this.digitacaoForm)" style="background-color: white;">
        <span class="input-group-btn">
          <a class="btn btn-info" onclick="OpenConsulta('prod');" id="pedido">
            <i class="glyphicon glyphicon-search"></i>
          </a>
        </span>
   </div>
 </div>

Input that receives the function

<div class="col-md-3">
  <label>Produto:</label>
  <br>
  <input type="text" class="form-control" formControlName="nomeProduto">
</div>
  • Why not put the subscrible return into a variable? It would not suit?

  • Explain the problem better with more details I try to help you.

  • an edit with html and a better explanation is needed

  • In fact, if I put in a variable, the name is not returned in the inputs I need, so I asked if there is any way to put two subscribes...

  • I edited by putting the basic html, with the input that calls the function, and with the input that receives, do you need any more information? If you need anything just let :D know

  • 1

    guy I think there’s something wrong... you don’t need to return anything to html... the angular is two-way data Binding you could add the return value of the request to a variable or model to work with the form... what might be a problem is if the form needs to be dynamic, but then you could use the form Uilder.... what version of the angular you are using?

  • @picossi am using angular 2, but I still can’t get the return way, to simplify, I want q the same value that returns from this function, also return directly to a model, so that it can call its value through the simple form "{example.example}}"

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.