1

I have an angular app using AWS Amplify for user management. In my main app component, i use auth.currentAuthentificatedUser to get user data to call APIs with the right token. But my API calls are done to fast, before the auth.currentAuthentificatedUser. How can I handle this?

Main app component:

import { Component } from '@angular/core';
import {AwsService} from './aws.service';


@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})

export class AppComponent {
  public async 
  title = 'app';
  username = '';
  constructor( public awsService: AwsService) {
    this.awsService.refreshsession(() => {
      this.username=this.awsService.userData.username
      });
  }  
  ngOnInit() {


  }
};

homepage component calling APIs

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css']
})




export class HomeComponent implements OnInit {


  constructor(public dialog: MatDialog, private _data: cotationBase, public router: Router, public awsService: AwsService, public callAPI: callAPI, public snackBar: MatSnackBar) {


  }


  ngOnInit() {

          this.callAPI.getAPI('https://api-dev.cloudyproject.pauset.fr/v0/providers',(response) => {
            console.log(response);
            this.awsImage = '../..'+response.aws.icon;
            this.azureImage = '../..'+response.azure.icon;

            },
            (response) => {
              console.log(response);},
            ) 

  }
4

1 回答 1

0

在您的模板中AppComponent继续使用该*ngIf指令。像这样:

<app-component>
    <home-component *ngIf="username">
    </home-component>
</app-component>

那样的话,它不会打开,HomeComponent直到你this.usernameAppComponent. 那有意义吗?

如果这个答案有效,请不要忘记接受它。

于 2018-09-10T21:11:10.990 回答