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

标签 javascript angularjs twitter-bootstrap

在 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/

相关文章:

javascript - 如何在多个平台使用 Neutralinojs os.runCommand

css - 如何用Bootstrap确认不同的移动平台?

html - 将三个自动排序列合并为一个

javascript - 使用 CSS 显示实际大小的图像

javascript - 检测是否从特定 URL 或域重定向

javascript - 使用 Handsontable 在同一列中对纯文本和 html 进行排序问题

javascript - 未调用 Angular 路由配置函数

javascript - AngularJS中计算价格总和

javascript - 使用 angularjs 将数据保存在 json 本地存储中

html - Flexbox 和 Bootstrap 如何在 Navbar 品牌区放置图片