相关疑难解决方法(0)

Typescript async/await不会更新AngularJS视图

我正在使用Typescript 2.1(开发人员版本)将async/await转换为ES5.

我注意到在我更改了在异步函数中绑定查看的任何属性后,视图不会使用当前值更新,所以每次我必须在函数结束时调用$ scope.$ apply().

示例异步代码:

async testAsync() {
     await this.$timeout(2000);
     this.text = "Changed";
     //$scope.$apply(); <-- would like to omit this
}
Run Code Online (Sandbox Code Playgroud)

此后text,视图中不会显示新值.

是否有任何解决方法,所以我不必每次手动调用$ scope.$ apply()?

angularjs typescript angularjs-scope

26
推荐指数
4
解决办法
7205
查看次数

标签 统计

angularjs ×1

angularjs-scope ×1

typescript ×1