Angular Chatroom Web App

I'm a beginner with Angular and am trying to build a chatroom application as a way to teach myself how to develop in the framework.

I'm using PHP and Yii for the backend to send RESTful data back to the angular application. I'm aware I could use NodeJS but have not got enough experience and wish to learn angular first.

In the ChatCtrl of my application there is a method called longPoll() which makes a request to the server like so:

$scope.longPoll = function (opts) {
    opts = opts || {
        lastMessageTime: '',
        lastSessionTime: ''
    };

    var params = '?lastMessageTime=' + opts.lastMessageTime +
        '&lastSessionTime=' + opts.lastSessionTime;

    // start up polling
    $http.get('/chat/poll' + params).success(function (res) {

        var user = res.items.user,
            message = res.items.message;

        // check session updates =========================================
        if (user) {
            if (user.totalCount > 0) {
                $(user.items).each(function () {
                    $scope.users[this.user_id] = this;
                });
            }
            opts.lastSessionTime = user.lastTime;
        }
        // ================================================================

        // check message updates =========================================
        if (message) {
            opts.lastMessageTime = message.lastTime;
            if (message.totalCount > 0) {
                $(message.items).each(function () {
                    $scope.messages[this.message_id] = this;
                });
            }
            opts.lastMessageTime = message.lastTime;
        }
        // ================================================================

        // loop again
        $timeout(function () { $scope.longPoll(opts); }, 1000);
    });
}

The server does an infinite loop each time checking if there is a change to the date_updated both the message table and the user table (joined to the session table to make sure they are logged in)

When a change occurs to the message or user tables (there may be more later) it passes the records down via JSON and then adds them to the $scope.messages and $scope.users so they can be viewed in the HTML:

<div ng-init="longPoll()" ng-controller="ChatCtrl">
    <ul id="nicklist" ng-cloak>
        <li id="nicklist-header">Users Online</li>
        <li ng-repeat="user in getArray(users)" ng-cloak>
            <a>
                <i class="icon-user"></i> {{user.username}}
            </a>
        </li>
    </ul>
    <ul id="messages">
        <li ng-repeat="msg in getArray(messages)" ng-model="msg" ng-cloak>
            <a class="message">
                <span class="date">[{{msg.date_added}}]</span>
                <span class="user">{{msg.username}}:</span>
                <span class="msg" ng-bind-html-unsafe="msg.message"></span>
            </a>
        </li>
    </ul>
</div>

The 'getArray()' function just converts the data into an array because I am storing both the $scope.messages and $scope.users as key: value objects so I can reference them later.

As this is my first proper Angular application I'm sure theres things I could do better. One thing I'm wondering about is a better way to recieve the data changes when the server sends them down. I originally was making multiple long poll requests to the server (one for messages and one for users) but now its just one which makes for less traffic and server load, this also means I can't use the $resource functionality of Angular as far as I know?

Can you tell me what could be improved, what here is considered good practice/bad practice?

Thanks

you may want to move the polling logic to a service and broadcast events to the controllers.

you can simply this significantly by using Node.js + socket.io