punith gowda
punith gowda

Reputation: 23

transition from ember service in Ember.js

generateDeviceCode(response) {
  let {
      encryptedactivationmessage,
      macvalueactivationmessage,
      encryptioncounter
  } = response.registerDetails;

  let softtoken = this.get('softtoken');

  softtoken.callSoftTokenService(
          'generateDeviceCode',
          macvalueactivationmessage,
          encryptedactivationmessage,
          encryptioncounter
      )
      .then(response => {
          let {
              deviceCode
          } = response;
          let userId = this.get('userId') || this.get('userPreference.userId');
          let groupId = this.get('groupId') || this.get('userPreference.groupId');

          let payload = {
              deviceCode,
              authorizationCode: this.get('memoizedFields.authorizationCode'),
              tokenSerialNumber: this.get('memoizedFields.tokenSerialNumber'),
              userId,
              groupId,
              notificationId: 'NA'
          };

          this.navigation.toRoute('digital.pinRegistrationFlow', {
              queryParams: {
                  initialState: 'setPin',
                  data: payload
              }
          });
      })
      .catch(err => {
          Logger.error(err);
      });
 },

When I try to go to ember route from ember service. I get the following error Cannot read property toRoute of undefined. But when I try the same code in the controller it works fine. Can anyone help me here please ?

Upvotes: 0

Views: 117

Answers (1)

user3614531
user3614531

Reputation: 11

If you are on a current-ish version of Ember you can inject the router as a service and use it to transition.

export default Ember.Service.extend({
     router: Ember.inject.service(),
     actions: {
         doIt() {
             this.get('router').transitionTo('somewhere');
         }
     }
}); 

Upvotes: 1

Related Questions