按钮删除方法如何首先获取可变数据而不是消息提示?我的代码附上了

问题描述 投票:0回答:2

我正在尝试使用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

实际上我需要在确认文本中显示结果中的一些数据

希望对你的建议表示感谢

angularjs model-view-controller angularjs-scope
2个回答
0
投票

尝试在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?")) {
                }
            });            
        }

0
投票

这可能有助于在调用函数时传递一些值

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?")) {
                }
            });            
        }
© www.soinside.com 2019 - 2024. All rights reserved.