Criar componente em Angularjs

Bom dia, gostaria da ajuda e do direcionamento de vcs prefessores e alunos de como eu posso componentizar meu código a seguir:
// fileName = nome da IMAGEM e do JSON exportado para gerar a animação
var fileName = “testeGif”;

      // função para executar a leitura do JSON
      function loadJSON(path, success, error) {
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function() {
          if (xhr.readyState === XMLHttpRequest.DONE) {
            if (xhr.status === 200) {
              if (success)
                success(JSON.parse(xhr.responseText));
            } else {
              if (error)
                error(xhr);
            }
          }
        };
        xhr.open("GET", path, true);
        xhr.send();
      } loadJSON(fileName + '.json', // o JSON é informado
        function(data) {
          var animate = document.createElement("div"); // cria a DIV que será criada a animação
          animate.setAttribute("id","animate"); // adiciona um ID a a DIV
          document.body.appendChild(animate); // insere a DIV no HTML
          document.getElementById("animate").style.background = "url(" + fileName + ".png)"; // informa o nome da imagem
          document.getElementById("animate").style.width = data.frames[0].sourceSize.w + "px"; // informa a largura da imagem
          document.getElementById("animate").style.height = data.frames[0].sourceSize.h + "px"; // informa a autura da imagem
          var bgpx, bgpy, bgp;
          for (var i = 0; i < data.frames.length; i++) {
            (function(ind) {
               setTimeout(function(){
                 bgpx = data.frames[ind].frame.x * (-1); // obtem o posicionamento X do frame
                 bgpy = data.frames[ind].frame.y * (-1); // obtem o posicionamento Y do frame
                 bgp = bgpx + "px " + bgpy + "px";
                 document.getElementById("animate").style.backgroundPosition = bgp; // muda o posicionamento da imagem para reproduzir o efeito
               }, 41.6666666667 * i);
            })(i);
          }
        },
        function(xhr) { console.error(xhr); }
      );

agradeço todos que puderem me ajudar a aprender a desenvolver componentes! abraços.