Last active
August 1, 2016 08:04
-
-
Save accessomnath/a3069ed9a732142f5e77ff0cd4a263b5 to your computer and use it in GitHub Desktop.
get online chat using 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 include('header.php') ?> | |
<div class="container"> | |
<div class="widget widget_volunteer_form"> | |
<div class="well" ng-app="chat" ng-controller="Chat"> | |
<?php if (isset($_SESSION['userid'])) { | |
$uid = $_SESSION['userid']; | |
$conQuerry = mysqli_query($conn, "Select * from Ccsbi_Users where UserId='$uid'"); | |
$row = mysqli_fetch_assoc($conQuerry); | |
$fName = $row['fName']; | |
?> | |
<form class="form-inline"> | |
Your name: <input type="text" ng-model="username" value="<?php echo $fName ?>"> | |
</form> | |
<?php } ?> | |
<div ng-cloak ng-repeat="message in messages"> | |
<em>{{message.from}}: </em>{{message.content}} | |
</div><br/> | |
<form class="form-inline" ng-submit="addMessage()"> | |
<input type="text" ng-model="message" placeholder="Message..."> | |
<button class="btn" type="submit"> | |
<i class="icon-reply"> Send</i> | |
</button> | |
</form> | |
</div> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.min.js"></script> | |
<script src="https://cdn.firebase.com/v0/firebase.js"></script> | |
<script src="https://cdn.firebase.com/libs/angularfire/0.5.0/angularfire.min.js"></script> | |
<script type="text/javascript"> | |
angular.module('chat', ['firebase']).controller('Chat', ['$scope', '$firebase', | |
function($scope, $firebase) { | |
var ref = new Firebase('https://angularfire.firebaseio.com/chat'); | |
$scope.messages = $firebase(ref.limit(15)); | |
$scope.username = '<?php echo $fName ?>'; | |
$scope.addMessage = function() { | |
$scope.messages.$add({ | |
from: $scope.username, content: $scope.message | |
}); | |
$scope.message = ""; | |
}}]); | |
</script> | |
</div> | |
</div> | |
<?php include('footer.php') ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment