Skip to content

Instantly share code, notes, and snippets.

@MichaelGooden
Created February 20, 2015 16:31
Show Gist options
  • Save MichaelGooden/398548543d80d13e8dca to your computer and use it in GitHub Desktop.
Save MichaelGooden/398548543d80d13e8dca to your computer and use it in GitHub Desktop.
Angular JS Skeleton
angular.module('myapp', ['myapp.services', 'myapp.controllers', 'myapp.directives'])
.config(function($sceDelegateProvider) {
$sceDelegateProvider.resourceUrlWhitelist([
'self',
'http://example.com/api/**'
]);
})
.config(function() {
//config functions here
})
.run(function($rootScope) {
$rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams){
$rootScope.loading.hide();
});
})
.run(function() {
//run blocks here
});
angular.module('myapp.controllers', [])
.controller('publicInfoCtrl', function($scope, $state, publicInfoService, publicInfoData) {
$scope.items = publicInfoData.data._embedded.public_info;
$scope.goToInfo = function(id) {
console.log('go to info: '+id);
$state.get('publicInfoDetail').data.id = id;
$state.go('publicInfoDetail');
};
});
angular.module('myapp.directives', [])
.directive('map', function() {
return {
restrict: 'E',
scope: {
onCreate: '&'
},
link: function ($scope, $element, $attr) {
console.log("map link");
function initialize() {
console.log("initialise");
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
var map = plugin.google.maps.Map.getMap($element[0], {
'backgroundColor': 'white',
'mapType': plugin.google.maps.MapTypeId.HYBRID,
'controls': {
'compass': true,
'myLocationButton': true,
'indoorPicker': true,
'zoom': true // Only for Android
}
});
map.clear();
map.off();
$scope.onCreate({map: map});
}
initialize();
}
}
});
angular.module('myapp.services', ['LocalStorageModule'])
.factory('scheduleService', function($http) {
var scheduleService = {};
scheduleService.getSchedule = function() {
if (!scheduleService.schedule) {
scheduleService.schedule = $http.get('http://example.com/api/schedule');
}
return scheduleService.schedule;
}
return scheduleService;
})
.factory('peopleService', function($http) {
var peopleService = {};
peopleService.getPeople = function() {
if (!peopleService.people) {
peopleService.people = $http.get('http://example.com/api/athlete');
}
return peopleService.people;
}
return peopleService;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment