gpt4 book ai didi

twitter-bootstrap - 如何从 Angular Bootstrap 模态调用函数(使用 angular-strap)?

转载 作者:行者123 更新时间:2023-12-04 09:00:54 25 4
gpt4 key购买 nike

我正在使用 Angular JS(使用 Angular Strap ),我正在尝试让保存确认对话框正常工作。

我有一个 clear 函数,如下所示:

$scope.clear = function(confirm) {
if ($scope.dirty && !confirm) {
$modal({template: '/save.html', show: true, backdrop: 'static'});
return;
}

// clear the data
}

然后我的模态对话框中有以下按钮:

<button type="button" class="btn" ng-click="clear(true);hide()">Discard Changes</button>
<button class="btn btn-primary" ng-click="hide()">Cancel</button>

无论我单击哪个按钮,这都可以很好地显示对话框,也可以隐藏它。但它从不调用 clear 函数。怎么回事?

最佳答案

您需要在 $modal 中发送作用域($scope)

$modal({ 
template: '/save.html',
show: true,
backdrop: 'static',
scope: $scope
});

现在您可以使用 $parent.clear() 或仅使用 clear(),因为范围已发送到模态。

关于twitter-bootstrap - 如何从 Angular Bootstrap 模态调用函数(使用 angular-strap)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16512259/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com