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

100
Visualizações
angular theating object as a string

I'm following this tutorial: https://www.tutorialesprogramacionya.com/angularya/detalleconcepto.php?punto=89&codigo=89&inicio=80. and it has the following part of code:

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

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  conversion!: string;
  potenciaNumero!: number;
  cantidad!: number;

  formularioConversion = new FormGroup({
    numerodecimal: new FormControl(''),
    base: new FormControl('octal'),
    potencia: new FormControl('2'),
    largo: new FormControl(true)
  });

  submit() {
    if (this.formularioConversion.value.base == "hexadecimal")
      this.conversion = parseInt(this.formularioConversion.value.numerodecimal).toString(16);
    if (this.formularioConversion.value.base == "octal")
      this.conversion = parseInt(this.formularioConversion.value.numerodecimal).toString(8);
    this.potenciaNumero = Math.pow(parseInt(this.formularioConversion.value.numerodecimal?), parseInt(this.formularioConversion.value.potencia));
    if (this.formularioConversion.value.largo)
      this.cantidad = this.formularioConversion.value.numerodecimal.length;
  }
}

the problem is that in the submit function i have the variable "numerodecimal" that is defined as an object but threated as a string. How can i solve this error?

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use typecasting to get over this. Here's some options in order of preference

parseInt(this.formulatrioConversion.value.numerodecimal || "")

parseInt(this.formulatrioConversion.value.numerodecimal as string)

parseInt(this.formulatrioConversion.value.numerodecimal as any)

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