S
S
Sapphiron5322015-07-08 21:54:27
JavaScript
Sapphiron532, 2015-07-08 21:54:27

How to call a function after ng-repeat render?

Hello.
I am writing a single-page application, where by clicking on a link using ajax I get data from the server. The received data is output using ng-repeat. The problem is that I use scripts to highlight code in html and in order for this highlight to appear, you need to call a function that updates these styles.
For example, I have <pre class="java">code</pre> $("pre.java").snippet("java") is called after the page is fully loaded, but if you try to call it after receiving an ajax response, then it is called after receiving, and not drawing on the page.
My directive:

app.directive("file", function() {
    return {
  restrict : "E",
  scope : true,
  controller : function($scope, $element) {
      $scope.fileName = $scope.file.fileName;
      $scope.fileContent = $scope.file.content;
  },

  link : function(scope, el, attr) {
      scope.fileName = scope.fileName;
      scope.fileContent = scope.fileContent;
  },
  template : 
  "<h3 class='title'>name: {{fileName}}</h3><pre class=\"java\">content: {{fileContent}}</pre>"
    }
});

Tried to call by condition $last. The function works, adds its classes to the block <pre>, but after that the "fileContent" is not replaced. Perhaps someone faced a similar problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2015-07-08
@Sapphiron532

Everything is simple, we make syntax highlighting a directive and there are no problems, angular itself will destroy everything.

_
_ _, 2015-07-08
@AMar4enko

Try $scope.$applyAsync or $scope.$$postDigest.
They take a function as an argument.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question