P
P
Philipp2015-01-30 07:07:58
Angular
Philipp, 2015-01-30 07:07:58

How to properly change the model in AngularJS?

There is the following working shit code (I can’t name it otherwise, because I’m still just learning).

'use strict';

angular.module('dumpsterApp.controllers', []).
    controller('AppCtrl', function ($scope, socket) {
      $scope.tl = 20;
      $scope.news = [];
      socket.on('news', function (data) {
        $scope.news.push(data); // засовываем данные
        if ($scope.news.length > $scope.tl) { 
          $scope.news = $scope.news.slice(-$scope.tl); // а теперь удаляем
        }
      });
    })

Actually, I have a suspicion that Angular updates the DOM immediately after pushing to the $scope.news array, and then again after the slice.
Tell me I'm wrong, or if I'm right, tell me how to do it right. Those. push and slice, and then do a refresh at home.
The essence of the thing is simple - a very rapidly changing table (several times per second, somewhere around 5-20). I want to achieve the minimum load on the processor. I heard there is some way to disable listening to external model changes (from the DOM side), but I don’t know how to do it right yet.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Dedukhin, 2015-01-30
@zoonman

You are wrong, dom is updated once.
If your table changes so often, then I assume that your question is due to the fact that you encountered some kind of brakes?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question