json - Can't seem to get $http service to work with AngularJS -


update: cleaned json , seems there's issue filter...

see original message below..

i javascript newbie , trying understand why application not working.

my goal application show 2 upcoming events json feed residing on same server. . here my live demo.

here's how have set up:

my view:

<body ng-app="listapp">  <div class="container" ng-controller="eventcontroller">  <h3>upcoming events:</h3>      <ul ng-repeat="event in events | upcomingevents | limitto: 2">         <li>{{ event.title }}</li>         <li>{{ event.start }}</li>     </ul>  </div> 

my module, controller, , filter:

var app = angular.module('listapp', []);  app.controller('eventcontroller', function($scope, $http){     $http.get('events.json').success(function(data) {              $scope.events = data;     }) });      app.filter('upcomingevents', function () { return function (input) {      var upcomingevents = [];      upcomingevents = input.filter(function (data) {         var currentdate = new date();          if ((data.start - currentdate) >= 0) {             return true;         } else {             return false;         }     });      upcomingevents.sort(function (a, b) {         return a.start - b.start;     });      return upcomingevents;   }; }); </body> </html> 

sample events json file:

[   {     "title": "all day event",     "start": "2015-07-13",     "allday": true   },   {     "title": "long event",     "start": "2015-07-05",     "end": "2015-07-13"   },   {     "title": "repeating event",     "start": "2015-07-15",     "allday": false   },   {       "title": "first time",       "start": "2015-07-31"   } ] 

if remove $http service , manually feed json event object controller, work correctly. it's once put in $http service, backfires.

anyone have leads on how fix? thanks!

what describe "sample events json file" javascript data structure, isn't valid json.

see http://json.org/ full definition of json, can have strings , numbers, not dates, , key names must enclosed in double-quotes, , strings may use double quotes around them, not single quotes.

you can validate json entering in http://jsonlint.com/.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -