在我的 Angular 应用程序(使用 ES6)中,我需要在从其他指令触发一些自定义事件后使用以下代码进行 ajax 调用:
class GridController {
constructor($scope, $rootScope, MyService) {
this.$scope = $scope;
this.$rootScope = $rootScope;
this.MyService = MyService
this.MyService.getItems(arg1, arg2).then((resp) => {
this.viewModel= resp;
});
this.$rootScope.$on('myEvent', (e, args) => {
this.MyService.getItems(arg1, args[1]).then((resp) => {
this.viewModel= resp;
});
}
});
}
问题是在成功 ajax 调用后 View 没有更新。 有什么想法为什么会发生这种情况吗?
最佳答案
可能是模型更新问题,请尝试此操作。
$scope.$apply();
关于javascript - AngularJS - 广播事件后更新指令的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38263517/