I'm writing a phone directory app with Cordova and thus using AngularJs for the logic.
I'm using this service to connect to the server (its a Diffusion Push server) and sending/recieving the messages with the data.

```
angular.module('directory.services', [])

.service('EmployeeService', function() {
    var clientSession;
    var employees = [];

    this.initConnection = function() {
        diffusion.connect({
            host : 'localhost',
            port : 8080,
            secure : false,
            principal : 'admin',
            credentials : 'password'
         }).then(function(session) {
             clientSession = session;
            session.on({
                [...] // Lots of session listerners
            });
           var subscription = session.subscribe('Company/Test');
           var stream = session.messages.listen('Company/Test');

           stream.on('message', function(message) {
               //Called when a message is recieved
                employees = JSON.parse(message.content);
                console.log(employees);
               // log shows me the data fine here
           });
        });
    }        

    this.sendMessage = function(content){
        clientSession.messages.send('Company/Test', content);
    }

    this.clearResult = function(){
        employees= []; 
    }
});

```

Controller:

```
angular.module('directory.controllers', [])

.controller('empListCtrl', function ($scope, $ionicPlatform, EmployeeService) {
    $scope.employees = EmployeeService.employees;
    $scope.searchKey = "";

    $scope.clearSearch = function () {
        // console.log() gives "undefined" for both variables here
        $scope.searchKey = "";
        EmployeeService.clearResult();            
    }

    $scope.search = function () {
        EmployeeService.sendMessage($scope.searchKey);
    }

    EmployeeService.initConnection();   
});

```

Problem:
I get the value from the server stream, and save it in my service variable.
But when I call clearSearch() from the controller, both employees variables are undefined, in the scope and in the service.

I get that there might be an error with the linking, but shouldnt then atleast the service still have the data?

I tried using an Object with an nested array for the linking, and tried to use watch in the controller. Both didnt work.

Any Ideas?