如何传递 ID 以从资产文件夹中读取 Json

How to pass an ID to read a Json from assets folder

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

正在使用该 ID 从本地存储获取 ID 值,尝试读取 json。 如何传递该 id 以读取特定的 json.

这是针对您的情况的解决方案,

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

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

非常适合 me.Let 试试这个,然后告诉我。

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