Export Angular input value

0

Good night, guys.

In Angular 6, I have the following code:

import { Component, OnInit } from '@angular/core'
import { FormGroup, FormBuilder } from '@angular/forms';

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

constructor(private formBuilder: FormBuilder) {}

ngOnInit() {
    this.formulario = this.formBuilder.group({
        pesquisa: [null],
    })
}
teste() {
    console.log(this.formulario.value.pesquisa)
}
}

How can I export the "this.formula" so that I can use it in a service?

I am capturing the data entered in an input via ngSubmit and I want to pass it to the url of an API (which is defined in a service).

I'm a beginner and I do not find solutions clear enough for my understanding.

Thank you.

    
asked by anonymous 07.06.2018 / 01:32

1 answer

1
ngOnInit() {
    this.formulario = this.formBuilder.group({
        pesquisa: [''],
    })
}
salvarForm() {
    const formVal=this.formulario.value;
    console.log(formVal);
    this.meuServico.salvarPesquisa(formVal).subscribe(respostaDoServer =>{ 
           console.log(respostaDoServer);
     });    
}
    
07.06.2018 / 09:27