jeudi 29 septembre 2016

In ember how do I wait for the result of a get to complete?

I have a simple admin page that does the following:

  beforeModel: function() {
    var permission = this.get('userService.currentUser.userPermission.isAdmin');
    if(!permission) {
      console.log("no permission");
      return this.transitionTo('index');
    }
  },

User and UserPermission are separate models. UserPermission is loaded async.

This works great if I navigate to /admin (the permission object is already cached), but if I go to /admin directly it does not, presumably because the userPermission object hasn't been loaded.

Is there a way to say "get the userPermission then evaluate"?




Aucun commentaire:

Enregistrer un commentaire