gpt4 book ai didi

javascript - 从 Angular Controller 打开 Bootstrap 弹出窗口

转载 作者:行者123 更新时间:2023-11-29 10:11:29 25 4
gpt4 key购买 nike

在 Angular 模板中我有两个 anchor ,第一个在弹出窗口中显示文本,第二个在弹出窗口中显示图像,就像这样:

<a ng-click="openPopup('Text')">Text popup</a><a ng-click="openPopup('Image')">Image popup</a>

我有两个不同的文本和图像弹出窗口。如果用户单击“文本弹出窗口”,我想打开文本弹出窗口。与图像相同。这是示例文本和图像弹出代码。

    <div class="modal fade" id="myTextModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" style="width:800px" role="document">
//Content goes here
</div>
</div>
<div class="modal fade" id="myImageModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" style="width:800px" role="document">
//Content goes here
</div>
</div>

在 Controller 中:

    $scope.openPopup = function(Value) {
if(Value=='Text'){
//open Text popup
}else{
//open Image popup
}
}

我正在使用 ui.bootstrap.modal 我该如何实现?

最佳答案

将模态框保存到两个 html 文件中并使用它来打开弹出窗口

$scope.openPopup = function(Value) {
if(Value=='Text'){
$scope.modalInstance = $modal.open({
templateUrl: 'views/text.html',
scope: $scope
});
}else{
$scope.modalInstance = $modal.open({
templateUrl: 'views/image.html',
scope: $scope
});
}
}

关于javascript - 从 Angular Controller 打开 Bootstrap 弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32689139/

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