使用loadData()加载2个文件

时间:2017-09-28 06:09:54

标签: angularjs

使用AngularJs我有一个智能表,我想用2个不同的文件绑定..是否可以在服务页面加载两个文件..请帮助

这是我用的:

//declare var require: any
import {Injectable} from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import { Observable } from 'rxjs/Rx';
@Injectable()
export class SmartTablesService {
  constructor(private http: Http) {
        }      
        smartTableData = [];
loadData() {
  console.log('loadData');
 //this.http.get('http://192.168.0.100:8000/json1')
  this.http.get('http://192.168.0.100:8000/medical')
  .subscribe((data) => {
            setTimeout(() => {
                var contactData = [];
                $.each(data.json(), function (key, value) {
                    var tempData = value;
                    contactData.push(tempData);
                });
                this.smartTableData = contactData;
            }, 1000);
        });
  }

  loadData2() {
    console.log('loadData');
   
   this.http.get('http://192.168.0.100:8000/cost')
    .subscribe((data) => {
              setTimeout(() => {
                  var contactData = [];
                  $.each(data.json(), function (key, value) {
                      var tempData = value;
                      contactData.push(tempData);
                  });
                  this.smartTableData = contactData;
              }, 1000);
          });
    }
getData(): Promise<any> {
  console.log("Promise");
  this.loadData();
  this.loadData2();
  //alert(this.loadData);
  return new Promise((resolve, reject) => {
      setTimeout(() => {
          console.log(this.smartTableData);
          //(this.smartTableData);
          resolve(this.smartTableData);
      }, 3000);
  });
}
}

但它无法正常工作...... 我想根据年份映射2个文件

医疗

[
	{
        "year": 2013,  
        "doctor": "Dr. Smith", 
        "illness": "Flu", 
        "apptdate": "3/12/2013",
	"details":"Patient had flu for 5 days. No medicines prescribed"
	},
	{
        "year": 2014,  
        "doctor": "Dr. ram", 
        "illness": "fever", 
        "apptdate": "31/12/2014",
	"details":"Patient had flu for 5 days. No medicines prescribed"
	}
]

费用

[
	{
        "year": 2013,  
	"cost": 260
	},
	{
        "year": 2014,  
	"cost": 360
	}
]

所以请告诉我一个最好的解决方案。

0 个答案:

没有答案