Collecting a list of documents from a factory for an AngularJS controller With this controller I'm injecting myFactory and using Array.push() to add the array response.documents to the this.documents array. I can't help feeling there's a better way without having to use _this.

function myController($route, myFactory) {
  'ngInject';

  this.$onInit = function() {
    const _this = this;
    const id = $route.current.params.someId;

    this.documents = [];

    myFactory.getData(id).then((response) =&gt; {

      console.log(response); // { "something": { "Id":1234 }, "documents":[{ "DocumentId":"2345", "DocumentName":"doc.docx" }] }
      console.log(response.documents); // [{ "DocumentId":"2345", "DocumentName":"doc.docx" }]

      response.documents.forEach((object) =&gt; {
        _this.documents.push(object);
      });
    });
  };
}
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);