Angular http request return has no return value

  public getList () {
    this.http.get("lottery/activity/activity-list", {
      // params: {pageSize: "20"},
    })
    .subscribe((res: any) => {
      if (res.resultCode == 200) {
        this.activityList = res.resultData;
        console.log(this.activityList);//
        return res.resultData; //tsservice 
      }
      // 
    }, (err: any) => {
    });
  }
  public OnInit () {
    this.activityList = this.activityService.getList();
    console.log(this.activityList);//
  }
Mar.16,2021
The

request is asynchronous, and your Synchronize code in OnInit will not print out naturally.


  1. first of all, it is useless for you to use return in subscribe in an observable.
  2. secondly, if your activityList is an array, you can use a more advanced usage if you traverse the generated activity through this array. Take advantage of AsyncPipe
    <ng-container *ngFor="let activity of activityList | async">
        <activity [options]="activity"></activity>
    </ng-container>
    
    public activityList: Observable<Array<any>>;
    
    ngOnInit() {
        this.activityList = 
            this.http.get('lottery/activity/activity-list', {params: {pageSize: '20'} });
    }
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b31348-2bd6d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b31348-2bd6d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?