S
S
Sergey2015-11-07 19:57:12
Angular
Sergey, 2015-11-07 19:57:12

How to call a function in angularjs?

app.controller("test", function($scope, $http){
  $scope.getTag = function(){
     $http.get('/api/v0/todos/tags').success(function(data){
       return data.items; // данные
     });		
  }
  
  $scope.showTasks = function (){
    var tag = $scope.getTag(); // что-то не так
    console.log(tag);		
  };
});

When I call showTasks in the template {{showTasks()}} repeatedly makes a call, it gives an error. What am I doing wrong in the request?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yaroslav Lyzlov, 2015-11-07
@Sergamers

10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
Here's an error for you. You call an asynchronous function many times, before one has time to fire, you call the second and so on, because of this, angular tries to call the digest cycle every time and stumbles upon the fact that it is already running.
To do this, you need to call asynchronous functions not so often and many times, read about debounce (to call a function, for example, once every half a second)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question