I am new to Angular, trying to read server side controller cookies in my 
typescript file. Below is my code. 
I am able read cookies successfully. But i am getting the results after a 
while not immediately. I want set username value in ngOnInit function..
 

public ngOnInit() {
        
      this.getAuthentication(); //want get value after this statement.
     console.log(this.userName); //returns undefined.

---- if(this.userName !=null)
{
this.loadUserInformation(this.userName);
}

console.log(this.userName); //returns value.

}

    public getAuthentication()
    {
        let user = new User();
        
        this.userService.AuthenticateUser(user)
            .subscribe(
            response => this.validateUserOnSuccess(response),
            response => this.validateUserOnError(response)
        );
    }

public validateUserOnSuccess(response: User) {
        //this.userObj = response;
        this.userName = response.UserName;
        //console.log(this.userName);
     }

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to