AngularJS $promise then() data undefined

后端 未结 4 701
伪装坚强ぢ
伪装坚强ぢ 2021-01-05 10:24

I am trying to get data assigned to a $scope variable. Inside my $promise.then() function it is displaying correctly but outside the function it shows as undefined. The foll

4条回答
  •  無奈伤痛
    2021-01-05 11:26

    It's a promise so it sets $scope.task after it returns. Until that return occurs $scope.task is undefined, which is what your second console.log is showing . At some later time the promise is resolved (completes) and $scope.task has a value, which is what your first console.log shows.

提交回复
热议问题