Created
December 2, 2013 11:59
-
-
Save Kaapiii/7748476 to your computer and use it in GitHub Desktop.
JSON output with PHP + Angular
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| '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