Skip to content

Instantly share code, notes, and snippets.

@clonn
Created April 19, 2014 04:36
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 clonn/11074265 to your computer and use it in GitHub Desktop.
Save clonn/11074265 to your computer and use it in GitHub Desktop.
sails.js simple chat gist, can check full status , https://github.com/clonn/sails-talk-demo
<div class="container" ng-app ng-controller="rootController">
<form action="/comment/create" method="POST" id="message-form">
<div class="form-group">
<input type="text" id="messge" ng-model="message" name="comments" placeholder="input comments ..." >
</div>
<button type="submit" class="btn btn-success">comment</button>
</form>
<div class="message">
<h1>Message leave here</h1>
<ul ng-repeat="comment in comments">
<li>{{comment.comments}}</li>
</ul>
</div><!-- /.message -->
</div>
function rootController($scope) {
socket.on('message', function messageReceived(message) {
if (message.verb == "create") {
$scope.comments.push(message.data);
// angular way
$scope.$apply();
}
});
socket.get("/comment", function(data) {
$scope.comments = data;
// angular way
$scope.$apply();
});
$("#comment-form").submit(function (e) {
e.preventDefault();
socket.post("/comment/create", {
comments: $scope.message
});
$scope.message = "";
});
}
<!-- add script before SCRIPT -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment