2016-09-29 70 views
0

如何在不使用后端的情况下以angularjs形式从json中调用数据。我写了这段代码,在这里我无法找到最后从json文件中获取数据的方法。有人请帮我从这里前进。如何在angularjs中从json中获取数据表单

代码

$scope.count = $scope.newPreAuth.length; 
    }; 

    //Delete newPreAuth - Using AngularJS splice to remove the preAuth row from the newPreAuth list 
    //All the Update newPreAuth to update the locally stored newPreAuth List 
    //Update the Count 
    $scope.deletenewPreAuth = function (preAuth) { 
     $scope.newPreAuth.splice($scope.newPreAuth.indexOf(preAuth), 1); 
     getLocalStorage.updatenewPreAuth($scope.newPreAuth); 
     $scope.count = $scope.newPreAuth.length; 
    }; 
}]); 

//Create the Storage Service Module 
//Create getLocalStorage service to access UpdateEmployees and getEmployees method 
var storageService = angular.module('storageService', []); 
storageService.factory('getLocalStorage', function() { 
    var newPreAuthList = {}; 
    return { 
     list: newPreAuthList, 
     updatenewPreAuth: function (newPreAuthArr) { 
      if (window.localStorage && newPreAuthArr) { 
       //Local Storage to add Data 
       localStorage.setItem("newPreAuth", angular.toJson(newPreAuthArr)); 
      } 
      newPreAuthList = newPreAuthArr; 

     }, 
     getnewPreAuth: function() { 
      //Get data from Local Storage 
      newPreAuthList = angular.fromJson(localStorage.getItem("newPreAuth")); 
      return newPreAuthList ? newPreAuthList : []; 
     } 
    }; 

}); 

的Json代码

PreAuth: 
====================== 

URL:http://dev.xxx.com:8080/xxx/preAuth 

TYPE:POST 

X-Auth-Token t3Z10HGEiYFdzq9lGtr18ycdeAAXmWBEI64rQAJcAte6Ka8Tz96IAhuXHSgpiKufsd 

{ 
    "preAuth": { 
    "claimbId": "newPreAuth", 
    "claimbStatus": "new", 
    "patientInfo": { 
     "patientName": "name", 
     "gender": "Male", 
     "dob": 950639400000, 
     "age": 21, 
     "contactNumber": 9987654356, 
     "tpaMemberId": 950639400121, 
     "policyNumber": "ABC12615627", 
     "corporateName": "ABC", 
     "EmployeeId": "XYZ10232", 
     "otherInsurance": { 
     "isOtherInsurance": true, 
     "playerName": "xyx", 
     "details": "sdfdsafdsfdsf" 
     }, 
     "familyPhysician": { 
     "isFamilyPhysician": true, 
     "physicianName": "fsdf"'c 
     "physicianContactNumber": 7878748728, 
     "address": { 
      "address1": "Hosa road", 
      "address2": "Basapura", 
      "city": "Bangalore", 
      "state": "Karnataka", 
      "country": "India", 
      "pincode": "560100" 
     } 
     }, 
     "isFamilyPhysician": false, 
     "address": { 
     "address1": "Hosa road", 
     "address2": "Basapura", 
     "city": "Bangalore", 
     "state": "Karnataka", 
     "country": "India", 
     "pincode": "560100" 
     } 
    }, 
    "medicalInfo": { 
     "illnessType": "cancer", 
     "clinicalFinding": "description", 
     "ailmentDuration": "2 months", 
     "ailmentHistory": "description", 
     "illnessCause": "alcohol", 
     "provisionalDiagnosis": [ 
     { 
      "diagnosisName": "abc", 
      "diagnosisICDCode": "121423" 
     }, 
     { 
      "diagnosisName": "xyz", 
      "diagnosisICDCode": "434543" 
     } 
     ], 
     "differentialDiagnosis": [ 
     { 
      "diagnosisName": "afasdbc", 
      "diagnosisICDCode": "12431423" 
     }, 
     { 
      "diagnosisName": "fdxyz", 
      "diagnosisICDCode": "434sdf543" 
     } 
     ], 
     "clinicalObservations": { 
     "BP": "120/80", 
     "CVS": "126", 
     "P.A.": "abc", 
     "R.S.": "aa", 
     "CNS": "dd", 
     "others": "others" 
     }, 
     "maternityDetails": { 
     "maternityType": "G", 
     "L.M.P.": 950639400000, 
     "E.D.D.": 950639400000 
     }, 
     "accidentDetails": { 
     "accidentCause": "xyz", 
     "accidentDate": 950639400000, 
     "isPoliceComplaint": true, 
     "firNumber": "asfsafds" 
     }, 
     "pastIllness": [ 
     { 
      "pastIllnessType": "Diabetes", 
      "isPresent": true, 
      "NoOfMonth": 2, 
      "NoOfYear": 5, 
      "illnessSince": 950639400000 
     }, 
     { 
      "pastIllnessType": "Hypertension", 
      "isPresent": true, 
      "NoOfMonth": 2, 
      "NoOfYear": 5, 
      "illnessSince": 950639400000 
     }, 
     { 
      "pastIllnessType": "Other", 
      "isPresent": false, 
      "NoOfMonth": 2, 
      "NoOfYear": 5, 
      "illnessSince": 950639400000 
     } 
     ] 
    }, 
    "treatmentInfo": {}, 
    "billingInfo": {}, 
    "documents": [ 
     { 
     "documentId": 12345, 
     "documentMetadata": { 
      "documentName": "discharge summary", 
      "date": 950639400000, 
      "version": "1.1", 
      "viewedStatus": false, 
      "link": "link to view/download document" 
     } 
     }, 
     { 
     "documentId": 12346, 
     "documentMetadata": { 
      "documentName": "medical summary", 
      "date": 950639400000, 
      "version": "1.0", 
      "viewedStatus": true, 
      "link": "link to view/download document" 
     } 
     } 
    ] 
    } 
} 
+0

这里有json数据错误“physicianName”:“fsdf”'c它应该像“physicianName”:“fsdfc”, – GANI

回答

0

我创建的样本,它的工作这样

 // Code goes here 
    var app = angular.module('app',[]); 
    app.controller('sample', function($scope,$http){ 
    $scope.name = "advaitha"; 
    $http.get('test.json').then(function(data){ 
    console.log(data.data); 
    }); 
}) 

这里是plunker example

使用HTML5 localStorage将需要您在使用或保存对象之前序列化和反序列化对象。

例如:

var myObj = { 
firstname: "kisun", 
lastname: "rajot", 
website: "https://www.kisun.com" 
} 
//if you wanted to save into localStorage, serialize it 
window.localStorage.set("empData", JSON.stringify(myObj)); 

//unserialize to get object 
var myObj = JSON.parse(window.localStorage.get("empData")); 

创建基于代码上午一个plunker能够保存并与您的代码检索JSON数据。 Please check here

+0

你能帮助我知道怎么可以用我的代码添加此代码,因为我有使用localstorage保存数据 – kam