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

205
Views
Ember - Cargando una URL dinámicamente para el botón

Nuevo en Ember, me pregunto cuál es la mejor manera de hacer esto:

 component.js import Component from '@ember/component'; import { inject as service } from '@ember/service'; export default Component.extend({ ajax: service(), url: '', async fetchUrl() { try { let result = await this.ajax.request( `api/urlgenerator` ); this.url = result.link; } catch (err) { this.errorHandler.handle(err); } }, init() { this._super(...arguments); this.fetchUrl(); }, });

y mi plantilla

 {{#card/banner}} <Banner @text="Template Button" @action={{hash text="Enable Launcher" onAction=(track-action (route-action "openUrl" this.url) ) }} /> {{/card/banner}}

openUrl es un método global simple responsable de abrir una URL externa

--

No estoy muy seguro de si esta es la forma correcta de hacerlo, en este momento no está funcionando, ya que tal vez debido al ciclo de vida del componente Ember, la variable se representa solo con el valor inicial (vacío '')

Sin embargo, si codifico la URL, por ejemplo, funciona bien.

¿Alguien me puede dar algún consejo al respecto?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

En el estilo de componente clásico, usaría this.set('url', result.link) en lugar de this.url = result.link . Sin embargo, en Ember moderno lo haría así:

 export default class MyComponent extends Component { @service ajax; @tracked url = ''; constructor() { super(...arguments); this.fetchUrl(); } async fetchUrl() { try { let result = await this.ajax.request( `api/urlgenerator` ); this.url = result.link; } catch (err) { this.errorHandler.handle(err); } } }

la URL de aviso debe ser @tracked .

about 4 years ago · Juan Pablo Isaza Report

0

En caso de que ayude a alguien, utilicé este enfoque La guía de promesas en propiedades calculadas

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!