我的 angularjs Controller 有问题。事情是这样的
我在单击按钮时触发异步方法,此方法显示一个带有输入文本的对话框,一旦关闭对话框,该文本就会添加到范围数组中,但是,第一次执行异步方法时, View 不反射(reflect)范围内的更改,如果我第二次单击并且再次调用该函数,那么我可以看到 View 中的所有更改(包括我所做的但没有立即看到的第一个更改)
这是我的示例代码
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); });
}
有什么想法吗?
最佳答案
将代码放入 $timeout 中以打开对话框。应该可以解决问题。
示例:
$scope.upload = function() {
...
$timeout(function() {
// put code here which opens dialog
}, 200);
}
关于javascript - ANGULARJS - $scope 在我第一次调用异步方法时不适用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38401302/