Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

198
Vistas
Ember - Loading an URL dynamically for button

New to ember, I wonder what is the best way to go about this:

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();
  },
});

and my template

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

openUrl is simple a global method responsible for opening an external URL

--

Not too sure if this is the right way to go about it, right now it is not working, since maybe due to ember component lifecycle, the variable gets rendered with the initial value only (empty '')

However, If I hardcode the url for example, it works fine.

Can someone give me some advice on it?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

In classic component style you would use this.set('url', result.link) instead of this.url = result.link. However in modern ember I would do it like this:

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);
    }
  }
}

notice url must be @tracked.

about 4 years ago · Juan Pablo Isaza Denunciar

0

In case it helps someone, I used this approach The Guide to Promises in Computed Properties

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda