Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

Argument of type 'AbstractControl' is not assignable to parameter of type 'string'.

Boa noite, estou com um erro e não estou conseguindo arrumar.

ERROR in src/app/photos/photo-form/photo-form.component.ts(33,30): error TS2345: Argument of type 'AbstractControl' is not assignable to parameter of type 'string'.

import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { PhotoService } from '../photo/photo.service';
import { Router } from '@angular/router';

@Component({
  selector: 'ap-photo-form',
  templateUrl: './photo-form.component.html',
  styleUrls: ['./photo-form.component.css']
})
export class PhotoFormComponent implements OnInit {

  photoForm: FormGroup;
  file: File;

  constructor(
    private formBuilder: FormBuilder,
    private photoService: PhotoService,
    private router: Router
  ) { }

  ngOnInit(): void {
    this.photoForm = this.formBuilder.group({
      file: ['', Validators.required],
      description: ['', Validators.maxLength(300)],
      allowComments: [true]
    });
  }

  upload() {
    const description = this.photoForm.get('description');
    const allowComments = this.photoForm.get('allowComments');
    this.photoService.upload(description, allowComments, this.file)
                    .subscribe(() => this.router.navigate(['']))
  }
}
2 respostas
solução!

Oi Dani, tudo bem?

Ainda não fiz este curso, mas dentro do método upload o description e o allowComments você não está pegando o valor deles.

Acredito que seja assim

const description = this.photoForm.get('description').value;
 const allowComments = this.photoForm.get('allowComments').value;

Ei Júlio, tudo bem e com você? Era isso mesmo, deu certinho! Muito obrigada!!

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software