小编kla*_*arn的帖子

ngOninit() 上的异步/等待

我正在尝试使用async/ await(第一次),但我无法理解它。

我在这里做错了什么:

tree.component.ts

export class TreeComponent implements OnInit {

  private routeSub: any;
  acronym: string;
  flare: any[];

  constructor(
    private location: Location,
        private route: ActivatedRoute,
        private http: HttpClient,
        private router: Router,
        private fileTreeService: FileTreeService
  ) {


  }
  ngOnInit(): void {
      this.routeSub = this.route.params.subscribe(
        params => {
            this.acronym = params.name
            this.fileTreeService.getFileTree(params.name).subscribe(item => {
                this.flare = item;

            });
        });
Run Code Online (Sandbox Code Playgroud)

文件树.service.ts

export class FileTreeService {

    res: any;

    constructor(private http: HttpClient) { }



    async getFileTree(acronym) {
        const headers = new HttpHeaders()
        this.res …
Run Code Online (Sandbox Code Playgroud)

asynchronous http angular

5
推荐指数
1
解决办法
6454
查看次数

标签 统计

angular ×1

asynchronous ×1

http ×1