Created
April 4, 2015 17:37
-
-
Save skelz0r/2cdbfccc02445948987e to your computer and use it in GitHub Desktop.
Devoxx 2015 : Ionic lab - Exo 2
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
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(); | |
} | |
}); | |
}) |
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
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 = ''; | |
}; | |
}); |
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
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