难以将模拟JSON数据访问到另一个角度文件中 [英] Difficulty accessing mock JSON data into another angular file

查看:45
本文介绍了难以将模拟JSON数据访问到另一个角度文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将模拟JSON数据从 data.mock.ts 文件访问为"data.stories.ts"文件.我尝试在故事文件中的 getWindowsData 函数中编写一些代码,但无法访问数据

I am trying to access mock JSON data from data.mock.ts file into ‘data.stories.ts’ file. I tried writing some code in getWindowsData function which is in stories file but I am unable to access the data

这是我的data.mock.ts文件代码

Here is my code for data.mock.ts file

export class Windows {
  public static readonly Windows = {
    Windows: [
      {
        WindowsValue: 993,
        WindowsYear: 1997,
      },
      {
        WindowsValue: 953,
        WindowsYear: 1873,
      },
    ],
  };
}

这是我的data.stories.ts文件代码

Here is my code for data.stories.ts file


export function HttpLoaderFactory(https: https) {
  return new TranslateHttpLoader(https, './i18n/', '.json');
}

@NgModule()
export class WindowsStoriesComponent {
  constructor(private translate: TranslateService, private localeService: LocaleService) {
    localeService.nameObservable().subscribe((name) => {
      translate.use(name);
    });
  }
}

      },
    };
  });

如何从模拟文件到故事文件中获取数据?

How can I get the data from mock file to stories file?

推荐答案

您正在做的是访问整个类,相反,您可以这样编写您提到的函数,

What you are doing is accessing the class as whole, Instead you can write in the function you mentiond, like this,

export function getEmpiricalPercentilesData(params: HttpParams) {

  // Returning the *empiricalPercentiles* variable(Mock Data) of the class
  return EmpiricalPercentiles.empiricalPercentiles;
}

这篇关于难以将模拟JSON数据访问到另一个角度文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆