2015-11-23 32 views
0

我目前我有这种方式来获得JSON列表。如何阅读没有HTTP的JSON文件获取Angular JS?

function() 
{ 
    return $http 
    (
     { 
      url: '../Content/Scripts/Languages/en.json', 
      method: "GET", 
      headers: 
      { 
       'Content-Type': 'application/json; charset=utf-8' 
      } 
     } 
    ); 
}, 

的原因,我不希望使用GET方法,因为它可以作为一种承诺,正因为如此,出现这种情况后,承诺将执行,任何功能,如果我从检索列表有空会让应用崩溃。

所以我想要的是检索列表,然后,我的其余功能可以执行一个列表填充。

有什么建议吗?

+0

你可以使用**回调函数**在成功的情况下**执行操作** **或**错误。 – deez4h

+0

我相信这是一个承诺......和我使用这些 promise.success ( 功能(数据) {$ = scope.Concepts数据; } ) .error ( 功能(的errorMessage ) { // Something } ); – Victor

+1

拥抱承诺:) –

回答

0

您可以使用RequireJS

你只需要这样:

define('yourModuleWithNgApplication', ['json!path/to/json/file.json'], function (json) { 
    // here you can access json variable, it will contain content of file.json 
});