Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

95
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!