Angularstrap - 模态框

时间:2013-07-23 07:02:46

标签: angularjs modal-dialog angularjs-directive angular-strap

我正在使用rails来构建我的应用程序。试图弹出一个带有angularstrap http://mgcrea.github.io/angular-strap/#/modal的模态框,他们给出了使用带有partials的模态框的例子。但是我想从同一页面调用div。他们用ng-template提到了一些东西。但是我没有得到任何东西。这方面的文件。有人知道吗?

3 个答案:

答案 0 :(得分:2)

您可以阅读ng-template here in the AngularJS docs。按如下方式实施:

<script type="text/ng-template" id="modal-template.html">
     <div>Content of Modal</div>
</script>

然后在你调用模态的地方,用modal-template.html替换对部分的引用:

<button data-toggle="modal" bs-modal="'modal-template.html'">Call to Action</button>

答案 1 :(得分:1)

在主html页面中定义你的TemplageCache如下:

<script type="text/ng-template" class="modal" id="/myTmpl.html">
    <div class="modal" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" aria-label="Close" ng-click="$hide()">
                    <span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">This title</h4>
                </div>
                <div class="modal-body">
                  This is content
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" ng-click="$hide()">Close</button>
                </div>
            </div>
        </div>
    </div>
</script>

然后在javascript中

$scope.showMyModal=function(){
    var myModal = $modal({placement:'center', animation:"am-fade-and-scale", templateUrl:'/myTmpl.html', show: true});
}

答案 2 :(得分:0)

如果你有一个内联(javascript中的html字符串)变量,那么ng-template就是这样。例如:

var t = "<div></div>";

t可能是您的ng-template。

不幸的是,我不知道如何做你想要的。

相关问题