Angular.js:根据用户选择使用json文件

时间:2018-06-22 03:56:55

标签: angularjs

我有多个json文件作为数据源。如何使用$ http.get()根据用户选择获取正确的json文件?

1 个答案:

答案 0 :(得分:0)

尝试类似

// Simple GET request example:
var fileName = 'myFile.txt' //name coming from where you call this service
$http({
  method: 'GET',
  url: '/someUrl/'+fileName
}).then(function successCallback(response) {
    // this callback will be called asynchronously
    // when the response is available
  }, function errorCallback(response) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
  });

使用api的替代方法

var fileName = 'myFile.txt'
$http({
    url: url: '/someUrl', 
    method: "GET",
    params: {fileName: fileName}
 });