2

I have a JavaScript function

function wantConversation(socket, callback) {
    if(socket)
    {
        socket.emit('user.wantConversation');
    }
    socket.on('user.getConversation', function(data) {
        callback(data);
    });
}

it Return a list of Conversations into an array and I call it into my Angular Controller

var panel_app = angular.module('panel-app', [])
    .controller('panel-controller', function($scope){
        wantConversation(socket, function(data) {
            $scope.conversations = data;
        });
    };
});

But my ng-repeat doesn't work :( i know problem is callback function.
and this is my Html

<div ng-repeat="x in conversations | filter: searchBox">
    {{ x.name }}
    // ...
</div>

1 Answer 1

4

You need to tell angular when the scope is modified outside of angular context so it can run a digest cycle to update view

Try

wantConversation(socket, function(data) {
    $scope.conversations = data;
    $scope.$apply();// tell angular to update view
});
Sign up to request clarification or add additional context in comments.

1 Comment

Important to realize that socket isn't part of angular

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.