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

163
Views
Cómo usar la variable fuera de ngOnInit

Tengo el siguiente código en mi ngOnInit:

 ngOnInit(): void { let selectedArea:any = null; let areas = document.querySelectorAll<SVGElement>('path'); // gets an array of all of the paths in the DOM areas.forEach((area) => { // for each svg path area.addEventListener('mouseover', function () { area.style.fill = '#2100b6'; // add hover }); area.addEventListener('mouseout', function () { area.style.fill = ''; // return to default on mouse out }); area.addEventListener('click', function () { if (selectedArea) { area.style.fill="black"; } if (selectedArea !== area.id) { selectedArea = area.id; area.setAttribute('class', 'selectedArea'); // changed area.style.fill="black"; } console.log(selectedArea); }); this.selectedRegion = selectedArea }); } selectedRegion : number = 0

"selectedArea" registra el código de la región seleccionada de un mapa SVG. Intenté incluir eso en la nueva variable "región seleccionada", pero no funcionó.

Entonces, quiero usar "selectedArea" fuera de ngOninit, pero no tengo idea de cómo hacerlo.

about 4 years ago · Juan Pablo Isaza
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!