how to get a json file located locally in angularjs -


hi using angularjs , want data locally built json file . tried using $http no luck. please tell alternate method

$http.get("job.json")     .success(function(response) {         $scope.big=response;           }); 

this method used , json code

{ "days": [{ "dayname": "sun,23 aug 2015", "date": "2015-08-23", "hours": "hoursarray(array24)" }, { "dayname": "mon,24 aug 2015", "date": "2015-08-24", "hours": "hoursarray(array24)" }, { "dayname": "tue,25 aug 2015", "date": "2015-08-25", "hours":"hoursarray(array24)" }, { "dayname": "wed,26 aug 2015", "date": "2015-08-26", "hours": "hoursarray(array24)" }] }

you should use factory feature of angular js , hee below complete javascript file. oh way fix json syntax error. must quote both value if use object type.

var mockdataforthistest = "json=" + encodeuri(json.stringify([ { "dayname": "sun,23 aug 2015", "date": "2015-08-23", "hours": "hoursarray(array24)" }, { "dayname": "sun,23 aug 2015", "date": "2015-08-23", "hours": "hoursarray(array24)" }, { "dayname": "sun,23 aug 2015", "date": "2015-08-23", "hours": "hoursarray(array24)" }, { "dayname": "sun,23 aug 2015", "date": "2015-08-23", "hours": "hoursarray(array24)" } ]));   var app = angular.module('myapp', []);  function peoplectrl($scope, $http) {  $scope.people = [];  $scope.loadpeople = function() {     var httprequest = $http({         method: 'get',         url: '/echo/json/',         data: mockdataforthistest      }).success(function(data, status) {         $scope.datas = data;     });  };  } 

here sample html example show json

<div ng-app="myapp"> <div ng-controller="peoplectrl"> <p>    click <a ng-click="loadpeople()">here</a> load data.</p> <table> <tr>     <th>id</th>     <th>first name</th>     <th>last name</th> </tr> <tr ng-repeat="data in datas">     <td>{{data.dayname}}</td>     <td>{{data.date}}</td> </tr> </table> </div> </div> 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -