0

How can I make a component route wait for a data befere to execute the controller and render the view. Similar to resolve of ngRoute and ui-router.

The documentation has this:

Angular Component Router

This only wait for the url change, ex:

//Old url
http://localhost/#/

// wait the promise (eg 1s) and then change the url to
http://localhost/#/heroes

But the view was changed immediately after the click in link, and then the url was changed, so weird!

This don't block the view render or controller execution (obviously).

Demo of this situation:

Code and preview: plunkr.co (click in heroes)

There are a similiar question that has no answers: Angular 1.5.x Component Router Resolve

Community
  • 1
  • 1
Marcos Kubis
  • 485
  • 1
  • 4
  • 11

1 Answers1

2

I found a solution:

This should be configured in the component definition:

.component('myComponent', {
    templateUrl: './my-compnent.html',
    controller: MyComponentCtrl,
    $canActivate: function($nextInstruction, $prevInstruction) {
      return Promise.resolve(<true or false>);
    }
})
Community
  • 1
  • 1
Marcos Kubis
  • 485
  • 1
  • 4
  • 11