Created
April 19, 2014 04:36
-
-
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
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
<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> |
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
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 = ""; | |
}); | |
} |
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
<!-- 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