$q Lazy Loading:
When a data needs to be requested more than once, and the next data requires the data that was previously requested, we can pass the data through a lazy load
The following code:
First: We need to get job information:
{ "id": "P3", "ImageUrl": "/image/company-3.png", "Name": "Sales", "CompanyID": "C3", "CompanyName": "Thousand Degrees", "Cityid": "C1", "CityName": "Shanghai", "Scaleid": "S3", "Scalename": "More than 500 people", "Industryid": "I1", "Industryname": "Internet", "Salaryid": "S2", "Salaryname": "3k-5k", "Experience": "1-3 Years", "Education": "Specialty", "Benefit": "Big Growth space", "description": "Job Responsibilities: \n1. Selling products;}
Second, through the job information inside the CompanyID get company information:
{ "id": "C1", "ImageUrl": "/image/company-1.png", "Name": "Mu class net", "Industry": "Mobile Internet", "State": "A Round", "People": "50-150 people", "Positionclass": [{ "id": "Jishu", "Name": "Technology", "Positionlist": [{ "id": "P1", "Name": "iOS front-end engineer", "CreatedDate": "2016-04-16 23:30", "Salary": "15k-25k" }] }, { "id": "yunying", "Name": "Operations", "Positionlist": [{ "id": "y1", "Name": "Operations Director", "CreatedDate": "2016-04-10 13:30", "Salary": "Above 25k" }] }]}
functiongetPosition () {vardef =$q. Defer (); $http. Get (' Data/position.json?id= ' +$state. params.id). Then (function(response) {$scope. Position=Response.data; Def.resolve (Response.data); }).Catch(function(Err) {def.reject (err); }); returndef.promise; } functionGetcompany (ID) {$http. Get (' data/company.json?id= ' + ID). Then (function(response) {$scope. Company=Response.data; }); } getPosition (). Then (function(response) {Getcompany (Response.companyid)});
Angularjs-webapp ($q)