无法将承诺结果保存在控制器中

Can't save the promise result in a controller

我在 angular 控制器中保存承诺时收到错误消息:

控制器是:

angular.module('app.controllers')
  .controller('questionController', function($log,QuizCreate,QuestionBank){

    QuestionBank.get().then(function(response){
      this.questions = response.data;
      $log.info(response.data);
    });

    // this.quiz = QuizCreate.generateQuiz();

    $log.info(this.questions);

  }); 

我收到的错误是:

TypeError: Cannot set property 'questions' of undefined

为什么???

这失败了,因为 this 引用了匿名函数而不是控制器。

angular.module('app.controllers')

.controller('questionController', function($log,QuizCreate,QuestionBank){
       var that=this;
QuestionBank.get().then(function(response){
  that.questions = response.data;
  $log.info(response.data);
});

// this.quiz = QuizCreate.generateQuiz();

$log.info(this.questions);

  });