1

I am new to Angular js 2.0. Currently I am working with a web application which is mainly intended for students. It has social media login for authorization. For that I have used angular2-social-login package. It works perfectly fine.

I have two pages 1) Home page 2)User-dashboard page.When I click on the sign-in button in the home page, the page will route to user-dashboard page. please see the code below (header.component.ts)

if((data.status == 1) && (data.redirect_url == 'dashboard')){
    this.router.navigate(['/dashboard']);
}

Now the code in app.route.ts

export const routes:Routes  =   [
   { path:'dashboard',component:UserDashboardComponent,canActivate: [AuthGuard] }, 
]

When the user clicks on the sign-in button on the Home page, the page route to User-dashboard page. The user-dashboard page need to display some details of the student includes name, profile pic, address etc. For this I have called a function in ngOnInit() of user-dashboard.component.ts. please see the code below

this.appService.getDashboardDatas(formdata)
                    .subscribe( (data) =>   {
                         this.dashboardData = data;
                         console.log(this.dashboardData);
                         return this.dashboardData;}

This code works fine, but the problem is that the data didnt receive on the view page(user-dashboard.component.html). When I console the dashboardData, I can see all the datas that I needed, But not binded to view page. If I refresh the page, I can see all datas in view page. I think the issue is that before loading the data view page is binded. How can I resolve this issue?

halfer
  • 19,824
  • 17
  • 99
  • 186
Sulu.MeanStack
  • 299
  • 2
  • 3
  • 18
  • 2
    Possible duplicate of [Wait for Angular 2 to load/resolve model before rendering view/template](http://stackoverflow.com/questions/34731869/wait-for-angular-2-to-load-resolve-model-before-rendering-view-template) – alex kucksdorf Apr 13 '17 at 10:56
  • Take a look at [this issue](http://stackoverflow.com/questions/34731869/wait-for-angular-2-to-load-resolve-model-before-rendering-view-template). Maybe the `Resolve` interface from [the documentation](https://angular.io/docs/ts/latest/api/router/index/Resolve-interface.html) will help you. – alex kucksdorf Apr 13 '17 at 10:57

0 Answers0