Collecting a list of documents from a factory for an AngularJS controller
In addition to what Blindman said, I would recommend avoiding using this in nested scopes , which is always confusing and error prone, by assigning documents to a local variable. i.e.

this.$onInit = function() {
  const id = $route.current.params.someId;
  let documents =this.documents = [];
  ...
  response.documents.forEach((object) =&gt; {
    documents.push(object);