These are chat archives for AngularClass/NG6-starter

15th
Oct 2016
Victor Nascimento
@vjoao
Oct 15 2016 11:15
Hello guys
I'm trying to implement a route resolve
but I cant access the resolved variable on controllers constructor
im trying this:
.config(($stateProvider) => {
  "ngInject";
  $stateProvider
    .state('welcome', {
      url: '/',
      component: 'welcome',
      resolve: {
        'currentAuth': function (Auth) {
          "ngInject";
          return Auth.$waitForSignIn();
        }
      }
    });
})
and trying to access it like this:
class WelcomeController {
  constructor(currentAuth) {
    "ngInject";

    console.log(currentAuth);
    this.name = 'welcome';
  }
}
Sergey Protko
@fesor
Oct 15 2016 11:18
@vjoao it this component controller or "global" controller?
Victor Nascimento
@vjoao
Oct 15 2016 11:18
component controller
Sergey Protko
@fesor
Oct 15 2016 11:18
then you should pass resolved value to component binding.
Victor Nascimento
@vjoao
Oct 15 2016 11:18
and the config belogns to the welcome component js file
Sergey Protko
@fesor
Oct 15 2016 11:20
.component('myComponent', {
    bindings: { currentAuth: '<' }
});
something like that. I didn't use uiRouter for a while
Victor Nascimento
@vjoao
Oct 15 2016 11:21
thanks, it worked =)
This changed a bit the way I was used to do
Sergey Protko
@fesor
Oct 15 2016 11:22
well... this is just a separation of concerns. Components responsible only for UI, not for state. You get state from within resolvers and pass it via bindings to components.
state changed - resolver updates value.
ideally
Victor Nascimento
@vjoao
Oct 15 2016 11:22
really cool =)