Skip to content

Instantly share code, notes, and snippets.

@Kaapiii
Created December 2, 2013 11:59
Show Gist options
  • Select an option

  • Save Kaapiii/7748476 to your computer and use it in GitHub Desktop.

Select an option

Save Kaapiii/7748476 to your computer and use it in GitHub Desktop.
JSON output with PHP + Angular
<?php
// Exammple function to output
funnction getFeed(){
$data = array();
$json = json_encode($data);
// Set the content-type - to avoid mime-type conversions
header('content-type: application/json; charset=utf-8');
// Set Origin to allow access by javascript,
// if no access-controll-allow-origin header is set
// an Error is raised
header("access-control-allow-origin: *");
die(json);
}
'use strict';
/**
* @author Markus Liechti <[email protected]>
* @copyright Comvation AG
*/
/**
* App name calendarEvents
* @type @exp;angular@call;module
*/
var calendarEventsApp = angular.module('calenderEvents', ['ngResource', 'ngAnimate']);
/**
* Controller to list the events
*
* @param {type} Controller name
* @param {type} param2
*/
calendarEventsApp.controller('EventListController', ['$scope', 'GetEventsService',
function($scope, GetEventsService){
$scope.events = GetEventsService.query();
console.log($scope.events);
}
]);
/**
* Service for fetching the last events
*
* @param {string} Service name
* @param {object} Angular resource module
*/
calendarEventsApp.factory('GetEventsService', ['$resource',
function($resource){
return $resource('http://www.example.ch/feed.js', {}, {
query: {method:'GET', params:{}, isArray:true}
});
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment