首页 > 解决方案 > 如何传递 ID 以从资产文件夹中读取 Json

问题描述

id = localStorage.getItem('currentUser')
this.http.get('./assets/id/profiles/admin.json')
                .subscribe(result => {
                  this.profile = result.json();
                });

使用该 id 从本地存储中获取 id 值,尝试读取 json。如何传递该 id 来读取特定的 json。

标签: typescriptassetsangular6

解决方案


这是您的方案的解决方案,

    let id = localStorage.getItem('currentUser');

    this.http.get(`assets/${id}/profiles/admin.json`)
        .subscribe(result=> {
            this.profile = result.json();
            //do some stuff 
        })

对我来说很完美。让我们试试这个,让我知道。


推荐阅读