Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- angular.module('myApp')
- .controller('SearchCtrl', function ($scope, socket) {
- $scope.results = [];
- $scope.doSearch = function() {
- socket.on('send', function () {
- this.results.push('Socket response!');
- });
- };
- })
- ;
- angular.module('myApp').factory('socket', function ($rootScope, socketFactory) {
- var socket = socketFactory();
- return {
- on: function (eventName, callback) {
- socket.on(eventName, function () {
- var args = arguments;
- $rootScope.$apply(function () {
- callback.apply(socket, args);
- });
- });
- },
- emit: function (eventName, data, callback) {
- socket.emit(eventName, data, function () {
- var args = arguments;
- $rootScope.$apply(function () {
- if (callback) {
- callback.apply(socket, args);
- }
- });
- });
- }
- };
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement