【发布时间】:2016-07-15 16:46:20
【问题描述】:
我的 angularjs 控制器有问题。是这样的
我在单击按钮时触发了一个异步方法,此方法显示一个带有输入文本的对话框,一旦关闭对话框,该文本就会添加到范围数组中,但是,当我第一次执行异步方法时,视图不反映范围内的更改,如果我再次单击并再次调用该函数,那么我可以在我的视图中看到所有更改(包括我所做的第一次更改但没有立即看到)
这是我的示例代码
var afterUpload = function (result) {
vm.testme = result;
vm.pdfs.list.push({ systemFilename: 'test', note: 'test' });
$scope.pdfs.push({ systemFilename: 'test', note: 'test' });
}
$scope.upload = function (files) {
var modalOptions = {
closeButtonText: 'Ok',
actionButtonText: 'Accept',
headerText: 'File upload',
bodyText: 'Please type the name of the file',
modalTemplate: '/MiniSpa/app/templates/modal/file-modal.html'
};
modalService.showModal({}, modalOptions).then(function(result) {
$scope.$evalAsync(function () { afterUpload(result); });
}
有什么想法吗?
【问题讨论】:
标签: javascript angularjs asynchronous angularjs-scope