Using queryParams in Controller init()


#1

What’s the best way to make use of queryParams in a Controller’s init() function? When I try something like this:

export default Ember.Controller.extend({
  queryParams: ['paymentId', 'PayerID'],
  paymentId: null,
  PayerID: null,
  init: function() {
    var paymentId = this.get('paymentId');
    var payerId = this.get('PayerID');
  }
});

When query parameters are specified in the URL, paymentId and payerId still return null in init(), I assume because it’s run before the queryParams are checked.

Why do I want to do this? To execute a PayPal payment after being redirected: https://developer.paypal.com/docs/integration/web/accept-paypal-payment/#execute-the-payment


#2

Controller initialization happens once, and when the object is created. Creation happens before the queryParams are attached to it. Any logic you’re trying to put here likely belongs in the route’s setupController.


#3

@jasonmit, thanks - would specifying it in setupController() be the same effect as setting it in model()?


#4

setupController is called once the model promise (if any) resolves