How i can edit in here? last time i did, and it made new post...

BTW, i apply it like this:

HTML:
<div class="message" data-ng-repeat="x in ChatModel.Messages">

JS:

var MessageList = function () { //Type Message
            this.values = [];
            this.push=function(username, message){
                this.values.push({UserName: username, Message: message});
                return;//throw exception
            };
            this.get=function(index) {
                return this.values[index];
            }
            this.toArray = function ()
            {
                return angular.copy(this.values);
            }
        }

        var groupMessages = new MessageList();

        $scope.ChatModel = {
            Logged: false,
            Message: '',
            Login: {
                UserName: '',
                UserId: ''
            },
            Messages: groupMessages.values//UserName, Message
        };


$scope.AddMessage = function (userName, message) {
            //$scope.ChatModel.Messages.
            groupMessages.push(userName, message);

            var divChatWindows = angular.element('#divChatWindow');


$scope.$apply();///////////////////////////////////////////////////////////////////////////////////////////////////
            //-var divNewMessage = '<div class="message"><span
class="userName">' + userName + '</span>: ' + message + '</div>';
            //-angular.element(divNewMessage).appendTo(divChatWindows);

            var height = divChatWindows[0].scrollHeight;
            divChatWindows.scrollTop(height);
        }

now, even with $apply, i'm one row late (sorry for bad language). i had,
but not already use jquery, but angular stuff, like angular.element, etc...
and what should i do with id? and does it matter if js find element by id
which is globally known, or by something else?

On Tue, Jun 16, 2015 at 9:00 AM, Sander Elias <[email protected]> wrote:

> Hi Hassan,
>
> Ok, You have 2 separate, but somewhat connected issues.
> Currently your msglist is making a fresh copy of the array of messages
> every time, This means, that on every invocation, (read every row in the
> table!) angalar needs to kick of an new digest cycle.. an endless loop.
> Just use the values array directly.
>
> Your second issue is $scope.$apply. You need that only if something is
> changing data inside your view from outside angular. This means, if you
> react to server push events for example. It looks like you got that
> covered.
>
> If you are really want to learn Angular correctly you should not use
> jQuery while learning. If you find the need to put an ID on a tag, you are
> probably doing it wrong, and there is a better way to accomplish that. If
> you are manipulating the DOM, you are probably doing it wrong too. Angular
> apps are data-driven, not dom-driven. All dom manipulation should be in
> directives, and even there you seldom need  really need it.
>
> Regards
> Sander
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "AngularJS" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/angular/U4ZV2RXAEMU/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to