Skip to content

Instantly share code, notes, and snippets.

@skelz0r
Created April 4, 2015 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skelz0r/2cdbfccc02445948987e to your computer and use it in GitHub Desktop.
Save skelz0r/2cdbfccc02445948987e to your computer and use it in GitHub Desktop.
Devoxx 2015 : Ionic lab - Exo 2
angular.module('app', ['ionic', 'firebase'])
.config(function($stateProvider, $urlRouterProvider){
$stateProvider
.state('app', {
url: '/app',
templateUrl: 'views/app.html',
controller: 'AppCtrl'
});
$urlRouterProvider.otherwise('/app');
})
.constant('Config', {
firebaseUrl: 'https://chat-devoxx-2015.firebaseio.com/skelz0r/'
})
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
angular.module('app')
.controller('AppCtrl', function($scope, RoomSrv){
'use strict';
$scope.messages = RoomSrv.getMessages();
$scope.sendMessage = function(message) {
RoomSrv.sendMessage({
content: message
},
$scope.messages);
$scope.message = '';
};
});
angular.module('app')
.service('RoomSrv', function($firebaseArray, Config) {
'use strict';
var firebaseRef = new Firebase(Config.firebaseUrl+'default/');
var service = {
getMessages: getMessages,
sendMessage: sendMessage
};
function getMessages() {
return $firebaseArray(firebaseRef);
};
function sendMessage(message, messages) {
messages.$add(message);
};
return service;
})
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment