【发布时间】:2014-05-18 05:34:48
【问题描述】:
我有一个看起来像这样的承诺链......
this.getFile(fileId).then(updateFile).then(displayAllDoneMessage);
其中getFile() 和updateFile() 分别使用ngResource 构造相应的JSON 调用,然后返回$resource.$promise。
链触发正常,但我在从 updateFile 中访问 $scope 时遇到问题
所以在getFile()我有
// this works
this.status.text = "fetching file"
但是在updateFile()我有
// this fails at runtime because "this" is not $scope
this.status.text = "updating file"
我做错了什么,或者我需要做些什么才能使$scope 在updateFile() 中可用?
我可能应该补充一点,我正在使用 TypeScript,以防万一。
【问题讨论】:
-
你使用的是“controller as”语法吗?
-
我不是,但这是我接下来要尝试的事情之一。
标签: angularjs promise angularjs-resource