我正在尝试使用Angular js方法更新记录,我的html就像,
<button type="button" ng-click="delete()">'Update'</button>
在angularjs中调用的delete方法是,
$scope.delete = function () {
tasksService.getData($scope.ids).then(function (d) {
var result = JSON.parse(d.data.data);
});
if (confirm("Sure to update status +'result.name'+ For building?")) {
}
}
此代码在点击时调用,但在点击OK
按钮之后移动到最后一行确认后调用getData
方法我得到的结果在var result
实际上我需要在确认文本中显示结果中的一些数据
希望对你的建议表示感谢
尝试在getData()成功时显示确认消息。这将使控件等待getData()的响应。
$scope.delete = function () {
tasksService.getData($scope.ids).then(function (d) {
var result = JSON.parse(d.data.data);
if (confirm("Sure to update status " + result.name + "For building?")) {
}
});
}
这可能有助于在调用函数时传递一些值
HTML
<button type="button" ng-click="delete(value)">'Update'</button>
JS
$scope.delete = function (value) { // passed value
tasksService.getData($scope.ids).then(function (d) {
var result = JSON.parse(d.data.data);
if (confirm("Sure to update status " + value.name + "For building?")) {
}
});
}