These are chat archives for jadjoubran/laravel5-angular-material-starter

20th
Jun 2016
shad0wfir3
@shad0wfir3
Jun 20 2016 11:06
Is anyone here?
Mark Kevin Besinga
@besingamkb
Jun 20 2016 13:37

good evening.

I put my header into a component. how can I refresh the header component when I have changes on other component? for example. when I click the login which is from other component then the header component will reload or init?

Jad Joubran
@jadjoubran
Jun 20 2016 14:47
Hi @shad0wfir3
@besingamkb the header component is not reloading because it is part of the ui-router parent state
however you could define a service or just use input ('=' or '<' data binding & output events (&))

for example,

<header is-authenticated="vm.is_authenticated"></header>

and in the header component you could have:
bindings:{
       isAuthenticated: '<'
}
I should probably do a screencast about this
Mark Kevin Besinga
@besingamkb
Jun 20 2016 14:52
@jadjoubran thank you very much
do you have screencast for authentication best practice? login, logout, etc..
Jad Joubran
@jadjoubran
Jun 20 2016 14:52
hmm not really
but they're baked in as of 3.2
is there anything in particular you're trying to do?
Mark Kevin Besinga
@besingamkb
Jun 20 2016 14:53
i am using the default login. I just want to show login link if not authenticated and logout link if authenticated without refreshing the page
this is what I do in logout. I created a new component called project-header and this is what logout do

    $onInit(){
        if (!this.auth.isAuthenticated()) {
            this.authenticated = false;
        }
    }

    logout() {
        if (this.auth.logout()) {
            this.state.go('app.login');
            this.$onInit();
        }
    }
Jad Joubran
@jadjoubran
Jun 20 2016 14:58
hmm why is this necessary?
  if (!this.auth.isAuthenticated()) {
            this.authenticated = false;
        }
Mark Kevin Besinga
@besingamkb
Jun 20 2016 15:00
i use that here.
<md-nav-item md-nav-sref="app.login" name="Login" ng-if="!vm.authenticated">Login</md-nav-item>
Jad Joubran
@jadjoubran
Jun 20 2016 15:00
okay.. if you want u could use say ng-if="vm.auth.isAuthenticated()"
Mark Kevin Besinga
@besingamkb
Jun 20 2016 15:01
ahh yes. thanks
Jad Joubran
@jadjoubran
Jun 20 2016 15:03
:D
Mark Kevin Besinga
@besingamkb
Jun 20 2016 15:04
does it works even if I didn't create an component for header?
Jad Joubran
@jadjoubran
Jun 20 2016 16:09
nop
because you need an instance of this.auth
Mark Kevin Besinga
@besingamkb
Jun 20 2016 16:14
okay thanks again jad :D
Jad Joubran
@jadjoubran
Jun 20 2016 17:18
sure!