![](/img/trans.png)
[英]JSON file not being read with Angular $HTTP Get in MEAN.JS application
[英]How to read JSON file without HTTP Get on Angular JS?
我目前有这种方法来获取JSON列表。
function ()
{
return $http
(
{
url: '../Content/Scripts/Languages/en.json',
method: "GET",
headers:
{
'Content-Type': 'application/json; charset=utf-8'
}
}
);
},
我不想使用GET方法的原因是因为它作为一个Promise起作用,因此,在Promise之后执行的任何功能都将执行,并且如果我从那里检索到的列表为空,则会使该应用程序崩溃。
所以我想要的是检索列表,然后,其余功能可以在填充列表的情况下执行。
有什么建议么?
您可以为此使用RequireJS 。
您将需要以下内容:
define('yourModuleWithNgApplication', ['json!path/to/json/file.json'], function (json) {
// here you can access json variable, it will contain content of file.json
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.